How to convert time from One Time Zone to another in Java?

By | August 12, 2019

In this blog post we will talk about How to convert time from One Time Zone to another in Java? This post also covers some code example so that things are clear to you.

Before proceeding for practical examples few things should be noted :

  • You should must know that util.Date class is not TimeZone aware, Object of this class does not store any time zone specific information.
  • It is clearly mentioned in the Java documentation for util.Date Class
  • The internal representation of the time inside Date object remains same for a given time, when we print the date object using System.out.println(date) method then date.toString() method is invoked it prints the date object value in local TimeZone of the JVM.
  • We can achieve custom TimeZone formatting using SimpleDateFormat The given time in milliseconds can be represented in different TimeZone using different TimeZone formatters using SimpleDateFormat.
  • In Java 8 we can achieve Custom TimeZone formatting using ZoneId, ZonedDateTime and DateTimeFormatter

Custom TimeZone formatting using SimpleDateFormat class example.

Sample output of program::

 Custom TimeZone formatting using java 8 APIs class

Sample output of program::

You may also like:

What are the standard ways for handling TimeZone in database transactions?

That’s all about  How to convert time from One Time Zone to another in Java?
If you have any feedback or suggestion please feel free to drop in blow comment box. 

Leave a Reply

Your email address will not be published. Required fields are marked *