在线计算器或准确的公式来计算自 1970 年到给定日期的毫秒数?
谁能给我一个在线计算器的链接或一个准确的公式来计算自 1970 年到给定日期的毫秒数? 我有一个计算这个的函数。但我想将我的函数的输出与java中某些内置函数的输出或某些进行相同计算的在线计算器的输出进行比较?我已经尝试过这个
Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT-4"));
cal.set(2000, 01, 21, 04, 33, 44);
long mynum=cal.getTimeInMillis();
System.out.println(mynum);
问题是“mynum”值每次运行都会变化。所以我无法进行正确的比较。
谁能指导我走正确的道路?
Can anyone give me the link to an online calculator or an accurate formula to calculate the number of milliseconds since 1970 to a given date?
i have a function which calculates this. But I want to compare the output of my function with the output of some inbuilt function in java or the output of some online calculator which does this same computation? I've tried out this
Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT-4"));
cal.set(2000, 01, 21, 04, 33, 44);
long mynum=cal.getTimeInMillis();
System.out.println(mynum);
The problem is that the "mynum" value keeps changing for every run.. So i can't do a correct comparison.
Can anyone direct me in the correct path?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它们不断变化,因为您设置了除毫秒之外的所有字段,因此毫秒是当前时间的毫秒数。
在设置其他字段之前调用
cal.set(Calendar.MILLISECOND, 0)
或cal.clear()
,并且值不应再发生变化。They keep changing because you set all the fields except the milliseconds, which are thus the number of milliseconds at the current time.
Call
cal.set(Calendar.MILLISECOND, 0)
orcal.clear()
before setting the other fields, and the values shouldn't vary anymore.