How to convert JavaScript date object to ticks

后端 未结 6 1783
[愿得一人]
[愿得一人] 2020-11-28 04:54

How should I convert JavaScript date object to ticks? I want to use the ticks to get the exact date for my C# application after synchronization of data.

6条回答
  •  爱一瞬间的悲伤
    2020-11-28 05:03

    That should be date.GetTime(). Be aware that C# and Javascript using different initial dates so use something like this to convert to C# DateTime.

    public static DateTime GetDateTime(long jsSeconds)
    {
        DateTime unixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, 0);
        return unixEpoch.AddSeconds(jsSeconds);
    }
    

提交回复
热议问题