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

  • Home
  • SEARCH
  • 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 8061817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:28:12+00:00 2026-06-05T10:28:12+00:00

Before anybody downvotes this question, I have browsed the web and StackOverflow for the

  • 0

Before anybody downvotes this question, I have browsed the web and StackOverflow for the situation that I am facing and did not find anything, hence I am posting as a new question.

I have a situation with java date and timezones.

Situation:

There are 2 servers on 2 different timezones, lets say PST and CST. I am receiving dateString(date as a string) from those servers. But, when I try to convert the string back to date, using SimpleDateFormat, the date information(Year, month, day, hours, minutes, seconds) is being converted properly. But the timezone information is not being preserved.

If I run my code on a server in EST, the pstDateString is converted to Date format, but the Timezone is being set to EDT, instead of PST.

I thought about it in many different ways but may be that I am stressed, I am not able to find a solution. Any help ?

Code block that would simulate the situation :

        DateFormat outDF1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:SS");
        outDF1.setTimeZone(TimeZone.getTimeZone("PST"));        
        String pstDateString = outDF1.format(new Date());

        DateFormat outDF2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:SS");
        outDF2.setTimeZone(TimeZone.getTimeZone("CST"));
        String cstDateString = outDF2.format(new Date());

        System.out.println("pstDateString "+pstDateString);
        System.out.println("cstDateString "+cstDateString);

        Date cstDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:SS").parse(cstDateString);
        Date pstDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:SS").parse(pstDateString);

        System.out.println("Date after format from string: "+pstDate);
        System.out.println("Date after format from string: "+cstDate);

Output Currently:

pstDateString 2012-06-07 10:26:689
cstDateString 2012-06-07 12:26:694
Date after format from string: Thu Jun 07 10:26:00 EDT 2012
Date after format from string: Thu Jun 07 12:26:00 EDT 2012

Output Expected:

pstDateString 2012-06-07 10:26:689
cstDateString 2012-06-07 12:26:694
Date after format from string: Thu Jun 07 10:26:00 PST 2012
Date after format from string: Thu Jun 07 12:26:00 CST 2012
  • 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-06-05T10:28:14+00:00Added an answer on June 5, 2026 at 10:28 am

    the java.util.Date class has no timezone, it is always in UTC. if you want to preserve the incoming timezone, you will need a new class which combines a Date and a TimeZone. you could create a simple holder class, or possibly use a Calendar.

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

Sidebar

Related Questions

Does anybody know? Couldn't find this question asked before, even though it seems fairly
Anybody encounter this kind of problem with CSS before? I have a header that's
Anybody seen this exception before, Google doesn't have a single post regarding the exception.
Ok before you think Not another question like this please read this first. I
I've asked this question before with no real answer. Can anybody help? I'm profiling
I'm looking around trying to see if anybody has asked this before. I don't
Before Anything: $.getJSON back button showing JSON return data not the page did not
Before writing this program,I thought that our is a package scope variable and my
Before explaining the problem I am facing,this is the code I am using: <!DOCTYPE
You'll have to forgive me on this one. I understand that the issue is

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.