new Date(long) gives different results

后端 未结 3 2062
孤独总比滥情好
孤独总比滥情好 2020-12-20 13:12

When I run this code:

System.out.println( \"XXX date=\" + new Date( 1311781583373L ) );

I get this result in Eclipse\'s JUnit runner:

3条回答
  •  时光说笑
    2020-12-20 14:06

    To specify the default timezone you can set the system property user.timezone. You can do this by passing it as an argument to the JavaVM (you may need to modify eclipse.ini or Maven equivalent config file):

    -Duser.timezone=
    

    ...or by setting it programmatically:

     System.setProperty("user.timezone", "");
    

    Or, if it is convenient you can specify a timezone which you use each time you print out the date:

    DateFormat myDateFormat = new SimpleDateFormat("");    
    myDateFormat.setTimeZone(TimeZone.getTimeZone("")); 
    ....
    System.out.println(myDateFormat.format(yourDate));
    

提交回复
热议问题