这段C#代码对应的Java代码是什么?
public static readonly DateTime Epoch = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc);
public static long Now
{
get { return (long)(DateTime.UtcNow - Epoch).TotalMilliseconds; }
}我知道我可以用Date对象来计算这个值,但是Java语言的Calendar和C#的DateTime有什么不同呢?
目前,我使用的是这段o‘Java:
public static long getCurrentTimeMillis(){
TimeZone here = TimeZone.getDefault();
Time time = new Time(here.toString());
time.setToNow();
return time.toMillis(false);
}但这两段代码之间的差异是显著的……C#代码比Java代码多出150多万毫秒...如何从Java代码中获得以毫秒为单位的正确时间?
发布于 2011-03-10 22:13:46
使用以下命令:
System.currentTimeMillis()这是具有毫秒分辨率的This时间,也就是自1970年1月1日午夜以来的毫秒,the epoch
将其转换为您的替代纪元:
long Offset = new Date(100, 0, 1, 0, 0, 0).getTime();
long DotNetTime = System.currentTimeMillis() - Offset;当然,计算一次此偏移量并将其设置为常量将是明智的。
发布于 2011-03-10 22:14:37
System.currentTimeMillis()是正确的
发布于 2011-03-10 22:15:43
试一试
System.currentTimeMillis()https://stackoverflow.com/questions/5260809
复制相似问题