How to get the current date and time

后端 未结 10 507
无人共我
无人共我 2020-11-29 16:59

How do I get the current date and time in Java?

I am looking for something that is equivalent to DateTime.Now from C#.

10条回答
  •  时光取名叫无心
    2020-11-29 17:59

    I prefer using the Calendar object.

    Calendar now = GregorianCalendar.getInstance()
    

    I find it much easier to work with. You can also get a Date object from the Calendar.

    http://java.sun.com/javase/6/docs/api/java/util/GregorianCalendar.html

提交回复
热议问题