Java and Javascript's Date objects store the values of milliseconds since 0:00 on January 1, 1970.
The .Net DateTime object stores the tick value since 12:00 on January 1, 0001, 1ticks=100 nanoseconds=0.1 microseconds.
Therefore, we can use the special moment of 0:00 on January 1, 1970 to convert the two, the code is as follows:
using System;namespace Extends{public static class DateTimeEx{#region DateTime Extendsprivate static DateTime dt = new DateTime(, , , , , , DateTimeKind.Utc);public static long ToJsTime(this DateTime dt){return (long)(TimeZone.CurrentTimeZone.ToUniversalTime(dt) - dt).TotalMilliseconds;}public static DateTime FromJsTime(this DateTime dt, long jstime){return TimeZone.CurrentTimeZone.ToLocalTime(dt.AddMilliseconds(jstime));}#endregion}} This is a DateTime extension class, adding two methods to the DateTime object to ToJsTime and FromJsTime .
Timezone conversion is implemented through TimeZone object.
The above is the relevant knowledge about the mutual conversion between Java and Javascript Date and .Net DateTime introduced to you by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support to Wulin.com website!