Here is a glossary:
Epoch time: indicates the number of "second (seconds)" from on January 1, January 1, 1970 to the present ".
Note that I quote "second (second) number" because the unit of measurement may be different in different projects and you need to carefully read the relevant documents. for example, in the Gmail notifications document of Gtalk API, the number of dates used ranges from on January 1, January 1, 1970 to the number of Millisecond (milliseconds) until now ".
Datetime of C. ticks: the number of one ten-millionth of a second from, January 1, January 1, 0001, or one hundred nanoseconds of a second, that is, the number of "one thousandth second.
Java date. gettime (): This method returns the number of Millisecond (milliseconds) as of, January 1, January 1, 1970 ".
Then perform a conversion:
1 second (second) = 1000 Millisecond (millisecond) = 10x100 one ten-millionth of a second (one thousandth second)
Okay, next is our Java conversion function.
Public static long getticks (string epochstr)
{
// Convert the target-epoch time to a well-Format String
String date = new java. Text. simpledateformat ("yyyy/mm/DD/hh/MM/SS"). Format (new date (long. parselong (epochstr )));
String [] DS = date. Split ("/");
// Start of the ticks time
Calendar calstart = calendar. getinstance ();
Calstart. Set (1, 1, 3, 0, 0, 0 );
// The target time
Calendar calend = calendar. getinstance ();
Calend. set (integer. parseint (DS [0]), integer. parseint (DS [1]), integer. parseint (DS [2]), integer. parseint (DS [3]), integer. parseint (DS [4]), integer. parseint (DS [5]);
// Epoch time of the ticks-Start Time
Long epochstart = calstart. gettime (). gettime ();
// Epoch time of the target time
Long epochend = calend. gettime (). gettime ();
// Get the sum of epoch time, from the target time to the ticks-Start Time
Long all = epochend-epochstart;
// Convert epoch time to ticks time
Long ticks = (all/1000) * 1000000) * 10;
Return ticks;
}
Use a diagram to describe:
|
Target time: January 1
I obtained the target time and the "Millisecond (millisecond) Count" from 0001 to 1970 respectively, and then added them together to get the "Millisecond (millisecond)" from the target time to 0001) number, and then convert the number to the number of ticks in one thousandth of a second.
maybe you will find out why the computing in December 0001 should not be in December January 3 since December January 1. this problem is also very strange to me, because I found that if the time difference is always two days since January 1, January 1, this is why I am waiting for the experts to solve it.