Is Calendar.getInstance().getTime() ever going to give me a different answer than new Date()?

后端 未结 2 1862
有刺的猬
有刺的猬 2021-02-15 13:23

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().getTi

2条回答
  •  南方客
    南方客 (楼主)
    2021-02-15 14:02

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

    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.

提交回复
热议问题