Convert Java Date to UTC String

前端 未结 7 503
予麋鹿
予麋鹿 2020-11-29 06:09

The java.util.Date toString() method displays the date in the local time zone.

There are several common scenarios where we want the data to be printed in

7条回答
  •  南笙
    南笙 (楼主)
    2020-11-29 06:15

    Well if you want to use java.util.Date only, here is a small trick you can use:

    String dateString = Long.toString(Date.UTC(date.getYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds()));

提交回复
热议问题