怎么将JavaScript时间戳与c#时间戳进行转换

  介绍

这篇文章主要介绍了怎么将JavaScript时间戳与c#时间戳进行转换,小编觉得不错,现在分享给大家,也给大家做个参考,一起跟随小编来看看吧!

Java可以用来干什么

Java主要应用于:1。网页开发;2。Android开发;3。客户端开发;4。网页开发;5。企业级应用开发;6。Java大数据开发;7。游戏开发等。

<>强实例如下:

using 系统;   using  System.Collections.Generic;   using 来;   using 包含;   using  System.Web.UI;   using  System.Web.UI.WebControls;   using  Newtonsoft.Json;      namespace  TestWeb   {   public 才能;partial  class  ajax : System.Web.UI.Page   {才能   ,,,protected  void  employee (object ,发送方,EventArgs  e)   ,,,{   ,,,,,if  (IsPostBack !)   ,,,,,{   ,,,,,,,//TestAjax ()   ,,,,,}   ,,,}      ,,,public  void  TestAjax ()   ,,,{   ,,,,,var  phone =, Request.Form (“phone");   ,,,,,var  authcode =, Request.Form (“authcode");   ,,,,,var  pt =, Request.Form [“pt"];,//js时间戳,new 日期().getTime(),例如:1429503106452      ,,,,,string  outputmsg =, string.Empty;      ,,,,,if  (phone  !=, null ,,, authcode  !=, null ,,, pt  !=, null)   ,,,,,{   ,,,,,,,DateTime  dtStart =, TimeZone.CurrentTimeZone.ToLocalTime (new  DateTime (1970,, 1,, 1));   ,,,,,,,//说明下,时间格式为13位后面补加4个“0”,如果时间格式为10位则后面补加7个“0”;   ,,,,,,,long  lTime =, long.Parse(时间+ pt  (pt.Length ==, 13, ?,“0000”,:,“0000000“));   ,,,,,,,TimeSpan  toNow =, new 时间间隔(lTime);   ,,,,,,,DateTime  dtResult =, dtStart.Add (toNow);,//得到转换后的时间      ,,,,,,,string  str =, dtResult.ToString ();   ,,,,,,,outputmsg =, OutMsg (new  ResponseInfo  {, success =,真的,,tag =, 100年,msg =,“成功,,});   ,,,,,}      ,,,,,Response.Write (outputmsg);   ,,,}      ,,,public  long  GetCurrentTicksForJs ()   ,,,{   ,,,,,System.DateTime  startTime =, TimeZone.CurrentTimeZone.ToLocalTime (new  System.DateTime (1970,, 1,, 1,, 0, 0, 0, 0));   ,,,,,DateTime  dtResult =, DateTime.Now;//获取时间,,,,,   ,,,,,long  t =, (dtResult.Ticks 作用;startTime.Ticks),/, 10000;//除10000调整为13位   ,,,,,return  t;   ,,,}      ,,,public  string  OutMsg (object  obj)   ,,,{   ,,,,,return  JsonConvert.SerializeObject (obj, Newtonsoft.Json.Formatting.Indented);   ,,,}      ,,,public  class  ResponseInfo   ,,,{   ,,,,,public  bool  success {组,得到,,,}   ,,,,,public  int  tag {组,得到,,,}   ,,,,,public  string  msg {组,得到,,,}   ,,,}      ,,,//?      ,,}   }& lt; % @  Page 语言=癱#“, AutoEventWireup=皌rue",后台代码=癮jax.aspx.cs",继承=癟estWeb.ajax", %比;      & lt; script 类型=拔谋?javascript"比;   var 才能;d =, new 日期(& lt; %=GetCurrentTicksForJs(), %祝辞);   警报才能(formatDate (d)),,      function 才能formatDate(现在),{   ,,,var  year =, now.getFullYear ();   ,,,var  month =, now.getMonth (), +, 1;   ,,,var  date =, now.getDate ();   ,,,var  hour =, now.getHours ();   ,,,var  minute =, now.getMinutes ();   ,,,var  second =, now.getSeconds ();   ,,,return  year    null   null   null   null   null   null   null   null   null   null   null   null   null   null   null

怎么将JavaScript时间戳与c#时间戳进行转换