Java longtime and C # date conversion

Source: Internet
Author: User

Package, can be used directly.

After encountering a long time in Java, use the datetime dt=convertjavadatetimetonettime (1207969641193) directly, so you can use it.

This string of date numbers: Java Long integer date, in milliseconds

 Public StaticDateTime Convertjavalongtimetodatetime (LongTime_java_long) {DateTime dt_1970=NewDateTime (1970,1,1,0,0,0);//Month Day time seconds    Longtricks_1970 = Dt_1970.ticks;//January 1, 1970 scale    LongTime_tricks = tricks_1970 + Time_java_long *10000;//Journal Date ScaleDateTime dt =NewDateTime (time_tricks). AddHours (8);//+ 8 hours, converted to datetime    returnDT;}

The number of milliseconds in Java statistics from January 1, 1970 represents the date. That is, for example, January 2, 1970, is 86,400,000 milliseconds after January 1. Similarly, December 31, 1969 is 86,400,000 milliseconds before January 1, 1970. The Java date class uses a long type to record these millisecond values. Because Long is a signed integer, the date can be before January 1, 1970, or after that. A long type represents a maximum positive value and a maximum negative value that can easily represent a 290,000,000-year period, which is suitable for most people's time requirements.
in Java, you can use System.currenttimemillis () to get the long form of the current time, which is marked as the number of milliseconds from January 1, 1970 to the current.

The long integer value for C # Date data is the number that elapsed since 12:00 midnight on January 1, 01, when the time is represented as a 100-nanosecond interval. This number is called ticks (scale) in the DateTime of C #. The DateTime type has a long integer read-only attribute named Ticks, which holds the value.
. NET computing time is not the same way, it is the unit of calculation is ticks, here you need to do a C # time conversion. This is said on the TICKS,MSDN:
A single tick represents one hundred nanoseconds or one ten-millionth of a second. The value of the represents the number of 100-nanosecond intervals that has elapsed since 12:00:00 midnight, Ja Nuary 1, 0001.
is from the beginning of the year of 1st midnight to a specified time of one out of 10,000 seconds, in order to compare with Java, say one out of 10,000 milliseconds.

It is important to note that because we are in the East eight area, we have to add 8 hours.

Reference:

http://blog.csdn.net/dragonpeng2008/article/details/8681435

Java longtime and C # date conversion

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.