Get Date Object In UTC format in Java

后端 未结 5 1957
不思量自难忘°
不思量自难忘° 2020-12-17 07:36

I have written following code. I want to get Date object in UTC format.

I am able to get expected date string in UTC using SimpleDateFormat. But using

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-17 08:34

    In java 8 , It's really easy to get timestamp in UTC by using java 8 java.time.Instant library :

    Instant.now();
    

    That few word of code will return the UTC Timestamp.

提交回复
热议问题