Java Calendar Timezone issue

Posted on 2009-05-01
Last Modified: 2013-11-23
Appreciate your help in pin pointing the issue in following code. I am creating a Calendar object of a specific time zone, but it is still displaying the local time zone.
e.g.  I have currently US/Eastern DST

Date currentDate = new Date();
TimeZone timeZone = TimeZone.getTimeZone("Canada/Newfoundland")
Calendar calTime = Calendar.getInstance(timeZone);

I am expecting that calTime will print the current time in NewFoundLand timezone, but when I print the value of calTime.getTime() it is printing time in US Eastern.  I tried to check at line 3 and line 4, at both lines it is printing US Eastern time.

What changes needed to make so that it print NewfoundLand Time?   Thanks,

Question by:fix2009
    LVL 92

    Expert Comment

    how do you display it, the wrapped date does *not* have any timezone associated with it
    So if you are using DateFormat to display the date then you need to set the timezone for the DateFormat


    Author Comment

    Ok. Let me simplify the question. How to display the NewfoundLand time being in a different timezone using Calendar or Date objects.
    LVL 92

    Accepted Solution

    DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm");
    String formatted = df.format(calTime.getTime());

    LVL 92

    Expert Comment

    or just:

    String formatted = df.format(currentDate);

    LVL 86

    Assisted Solution

    >>How to display the NewfoundLand time being in a different timezone using Calendar or Date objects.

    DateFormat df = DateFormat.getInstance();

    Open in new window


    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    MaxSpan challenge 9 51
    java JDK Download 7 49
    sumHeights  challenge 17 50
    maven java path setting 5 33
    Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
    Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
    Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
    This video teaches viewers about errors in exception handling.

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now