When I create a new Date
object, it is initialized to the current time but in the local timezone. How can I get the current date and time in GMT?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
Use java.time package and include below code-
ZonedDateTime now = ZonedDateTime.now( ZoneOffset.UTC );
or
LocalDateTime now2 = LocalDateTime.now( ZoneOffset.UTC );
depending on your application need.
Actually not time, but it's representation could be changed.
Time is the same in any point of the Earth, but our perception of time could be different depending on location.
This definitely returns UTC time: as String and Date objects !
this is my implementation:
Here is another way to get GMT time in String format
If you want to avoid parsing the date and just want a timestamp in GMT, you could use: