I want to get local time of different time zones using Java code. Based on the time zone passed to the function I need that time zone's local time. How to achieve this?
相关问题
- 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
Java 1.8 provides you with some new classes in package
java.time
:I wrote the following program to get time for all the Timezones available, see if this helps...
In Java 8, you can use the
ZonedDateTime.now(ZoneId zone)
method:I'd encourage you to check out Joda Time, an alternative (but very popular) to the standard Java date and time API:
http://joda-time.sourceforge.net/index.html
Using Joda Time, I think this is what you what:
You just need to know the standard ID for the time zone in question, such as UTC.