先来个名词解释:
Epoch time:指从1970年1月1日零时起到现在为止的"second(秒) 数".
注意我给"second(秒) 数"加了引号,是因为在不一样的项目中,计量单位可能是不同的,需要仔细的阅读相关文档.比如Gtalk Api的Gmail Notifications文档中,所使用的date数为从1970年1月1日零时起到现在为止的"millisecond(毫秒) 数".
C#的Datetime.ticks:指从0001年1月1日零时起到现在为止的one ten-millionth of a second数量,或者one hundred nanoseconds of a second数量,也就是"千万分之一秒"的数量.
java的Date.getTime():这个方法返回目标时间到1970年1月1日零时为止的"millisecond(毫秒) 数".
然后来做个转换:
1 second(秒)=1000 millisecond(毫秒)=10 x 100 0000 one ten-millionth of a second(千万分之一秒)
好了,接下来是我们的java转换函数复制内容到剪贴板代码:
Epoch time:指从1970年1月1日零时起到现在为止的"second(秒) 数".
注意我给"second(秒) 数"加了引号,是因为在不一样的项目中,计量单位可能是不同的,需要仔细的阅读相关文档.比如Gtalk Api的Gmail Notifications文档中,所使用的date数为从1970年1月1日零时起到现在为止的"millisecond(毫秒) 数".
C#的Datetime.ticks:指从0001年1月1日零时起到现在为止的one ten-millionth of a second数量,或者one hundred nanoseconds of a second数量,也就是"千万分之一秒"的数量.
java的Date.getTime():这个方法返回目标时间到1970年1月1日零时为止的"millisecond(毫秒) 数".
然后来做个转换:
1 second(秒)=1000 millisecond(毫秒)=10 x 100 0000 one ten-millionth of a second(千万分之一秒)
好了,接下来是我们的java转换函数复制内容到剪贴板代码:
-
Java code
-
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; }