What will be the output of this date/time program?

By | August 12, 2019

In this post we will learn about one of very tricky java programming interview question where interviewer will give you code snippet and you will have to find the output of given code snippet.

Sample output of program:

date1 = Mon Aug 12 14:19:09 IST 2019
date2 = Mon Aug 12 14:19:09 IST 2019

Explanation of above output:

Output of both the System.out.println will be same date value because Date class object is always printed in local TimeZone and changing the TimeZone on Calendar class does not alter the underlying milliseconds value from the epoch time (Since January 1, 1970 00:00:00.000 GMT).

You may also like:

What are the standard ways for handling TimeZone in database transactions?
How to convert time from One Time Zone to another in Java?

Thanks for visiting this blog.
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 *