What is the default timezone for java.util.Calendar.?

后端 未结 4 1005
一整个雨季
一整个雨季 2021-02-09 16:26

Code

public String testDate(){ 
      TimeZone.setDefault(TimeZone.getTimeZone(\"US/Eastern\"));
      Calendar fromDate = Calendar.getInstance(         


        
4条回答
  •  梦如初夏
    2021-02-09 17:11

    You mention "cdate", and I notice there is a field inside the Calendar object called cdate. In running your sample code, I see that the cdate field is indeed initialized to 2013-12-10T00:00:00.000Z (it now being 24 hours later of course).

    So? I don't know why you are looking at internal fields of a class when you are never going to directly use them.

    Your solution, then, is to ignore it. Don't worry about the cdate field of your Calendar; worry about things that actually affect your program.

    The toString() of a Calendar is not very pretty and is intended for debugging; you should call cal.getTime() which will give you a java.util.Date that you can then print out either directly or by using a java.text.DateFormatter.

提交回复
热议问题