How to calculate date in JAVA
JAVA statistics show the number of milliseconds from January 1, 1970 to indicate the date. That is, for example, January 2, 1970 is 86,400,000 milliseconds after January 1. Similarly, December 31, 1969 was 86,400,000 milliseconds before January 1, 1970. Java's Date class uses the long class type to record these millisecond values. Because long is a signed integer, the date can be before January 1, 1970, or after this. The maximum positive and maximum negative values represented by the Long type can easily represent 290,000,000 years of time, which is suitable for most people's time requirements.
In Java, you can use () to get the long form of the current time, and its marked form is the number of milliseconds from January 1, 1970 to the current milliseconds.
Date calculation method in C#
The long integer value of C# date-type data is the number of time elapsed at 100 nanosecond intervals since midnight on January 1, 0001. This number is called Ticks in the DateTime of C#. The DateTime type has a long integer read-only property named Ticks, which holds this value.
Convert Java's long integer time to C# time:
It should be noted that we are in East Eighth District and we are using, so it takes 8 hours to add in the last.
long time_JAVA_Long = 1207969641193;//Java long integer date, milliseconds in unitsDateTime dt_1970 = new DateTime(1970, 1, 1, 0, 0, 0); long tricks_1970 = dt_1970.Ticks;//January 1, 1970 scalelong time_tricks = tricks_1970 + time_JAVA_Long * 10000;//Log date scaleDateTime dt = new DateTime(time_tricks).AddHours(8);//Convert toDateTime
The following source code is usedSimpler
TimeSpan ts=new TimeSpan( - new DateTime(1970, 1, 1, 0, 0, 0).Ticks); (long);
C# Time to Java Time
/// Date conversionpublic DateConvert(DateTime date){ DateTime nTime = (-8); long ctime = ; long c1970 = new DateTime(1970,1,1).Ticks; long java_ticks = (ctime - c1970)/10000; jDate = new (java_ticks); return jDate; }
For more information about Java and C# date and time, please click the relevant link below