How to set java timezone?

前端 未结 6 1384
囚心锁ツ
囚心锁ツ 2021-01-05 11:53

My system time differs from what java\'s new Date() tells (+ 4 hours),
so I think it\'s because some java settings.
How can I make java time to be always as my linu

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-05 12:16

    Calendar calendar = Calendar.getInstance(TimeZone.getDefault());
    Date myDate = calendar.getTime();
    System.out.println(myDate);
    

    Is this code printing the right date/time? Else, there's some other problem.

提交回复
热议问题