The Java and Javascript date objects are stored inside the millisecond value since 0 o'clock January 1, 1970.
The. Net DateTime objects are stored internally from the tick value since 12 o'clock January 1, 01, 1ticks=100 nanoseconds =0.1 microseconds.
So, we can use the January 1, 1970 0 O'Clock this special time to convert the two, the code is as follows:
Using System;
Namespace Extends
{public
static class Datetimeex
{
#region DateTime Extends
private 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 that adds Tojstime and Fromjstime two methods for DateTime objects.
It implements time zone conversions by TimeZone objects.
The above is a small set to introduce Java and Javascript Date and. Net DateTime between the exchange of knowledge, hope to be helpful to everyone, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!