Calendar.getInstance()。getTime()是否会给我一个与新Date()不同的答案? [英] Is Calendar.getInstance().getTime() ever going to give me a different answer than new Date()?

查看:635
本文介绍了Calendar.getInstance()。getTime()是否会给我一个与新Date()不同的答案?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试整合一些非常混乱的代码,但我想确保我不会破坏它。在某些地方,我看到日期创建为 Calendar.getInstance()。getTime(),而在其他地方,它只是 new Date()。如果我将它们全部转换为 new Date(),或者有什么理由我可能想要使用另一个吗?

I'm trying to consolidate some code that is very messy but I want to make sure I don't break things. In some places I see a date created as Calendar.getInstance().getTime() and in others it's just new Date(). Will it break things if I convert them all to new Date() or is there some reason I may want to use the other?

推荐答案

理论上,不,因为java.util.Date和java.util.Calendar.getInstance()最终都使用System.currentTimeMillis()来返回当前时间。

In theory, no, because both java.util.Date and java.util.Calendar.getInstance() eventually use System.currentTimeMillis() to return the current time.

然而,日历实现会考虑其他因素,例如Locale,或者如果语言环境是JP或TH ......您可以在源代码中看到两个班级。

The Calendar implementation, however, takes other things into consideration, like the Locale, or if the locale is JP or TH... you can see that in the source code of both classes.

这篇关于Calendar.getInstance()。getTime()是否会给我一个与新Date()不同的答案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆