The conversion between the Java and Javascript Date and the. Net DateTime _java

Source: Internet
Author: User
Tags static class

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.