Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6742843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:53:28+00:00 2026-05-26T11:53:28+00:00

I understand that java Date is timezoneless and trying to set different timezone on

  • 0

I understand that java Date is timezoneless and trying to set different timezone on Java Calendar wouldn’t convert date to an appropriate Time Zone. So I have tried following code

 public static String DATE_FORMAT="dd MMM yyyy hh:mm:ss";
 public static String CURRENT_DATE_STRING ="31 October 2011 14:19:56 GMT";
 DateFormat dateFormat =  new SimpleDateFormat(DATE_FORMAT);
 dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
 System.out.println(dateFormat.parseObject(CURRENT_DATE_STRING));

but it outputs wrong date Mon Oct 31 16:19:56 when it must be 12:19:56?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T11:53:29+00:00Added an answer on May 26, 2026 at 11:53 am

    The main issue here is your date format string is using hh (12-hour clock) instead of HH (24-hour)

    Secondly, your date format should specify that your date string contains the timezone.
    (Alternatively you could uncomment the commented line, to tell it the correct timezone).

    Thirdly, you should use a DateFormat to output the time to screen aswell…

    Finally, UTC = GMT, so the UTC time is also 14:19:56

    (GMT, ‘British Winter Time’, is the same as UTC, whereas BST is one hour ahead)

    public class DateFormatTest {
        public static String DATE_FORMAT="dd MMM yyyy HH:mm:ss z";
         public static String CURRENT_DATE_STRING ="31 October 2011 14:19:56 GMT";
    
        public static void main(String[] args) throws ParseException {
             DateFormat dateFormat =  new SimpleDateFormat(DATE_FORMAT);
             //dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
             Date d= dateFormat.parse(CURRENT_DATE_STRING);
             dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
             System.out.println(dateFormat.format(d));
        }
    }
    

    Output: 31 Oct 2011 14:19:56 UTC

    HTH

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please understand firstly that I fully understand that Java will return a String when
I understand that BigDecimal is recommended best practice for representing monetary values in Java.
I have an exe that I know was written in java. I understand that
This question is for the java language in particular. I understand that there is
For years and years, I've tried to understand the part of Java specification that
I'm a newbie on Java EE and got a problem that I don't understand
I understand that double locking in Java is broken, so what are the best
I understand that Java's native swing UI elements do a number of rendering optimizations
I understand that some countries have laws regarding website accessibility. In general, what are
I understand that there are several ways to blend XNA and WPF within the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.