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 8141159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:24:36+00:00 2026-06-06T12:24:36+00:00

I am trying to convert a Date to String and then back again to

  • 0

I am trying to convert a Date to String and then back again to Date. However I found out that the final date is different from the original date, what gives?

    //1975-06-20
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.YEAR, 1975);
    cal.set(Calendar.MONTH, 5);
    cal.set(Calendar.DAY_OF_MONTH, 20);
    cal.set(Calendar.HOUR, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    System.out.println(cal);

    Date originalDate = cal.getTime();
    System.out.println("Date 1: " + originalDate.toString());

    SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy");
    Date date = sdf.parse(originalDate.toString());
    System.out.println("Date 2: " + date.toString());

The output from the above code is:

cal: java.util.GregorianCalendar[time=?,areFieldsSet=false,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="Asia/Singapore",offset=28800000,dstSavings=0,useDaylight=false,transitions=9,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=1975,MONTH=5,WEEK_OF_YEAR=26,WEEK_OF_MONTH=5,DAY_OF_MONTH=20,DAY_OF_YEAR=179,DAY_OF_WEEK=4,DAY_OF_WEEK_IN_MONTH=4,AM_PM=1,HOUR=0,HOUR_OF_DAY=16,MINUTE=0,SECOND=0,MILLISECOND=333,ZONE_OFFSET=28800000,DST_OFFSET=0]
Date 1: Fri Jun 20 12:00:00 SGT 1975
Date 2: Fri Jun 20 11:30:00 SGT 1975
  • 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-06T12:24:37+00:00Added an answer on June 6, 2026 at 12:24 pm

    Probably because of the timezone change in Singapore on 1982 (+ 30 minutes).

    http://www.timeanddate.com/worldclock/timezone.html?n=236&syear=1980

    The SimpleDateFormat take the SGT as UTC+8 when parsing the date, and convert it to UTC+7.5, which is the SGT before 1982. Hence the date is off by 30 minutes.

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

Sidebar

Related Questions

I'm trying to convert an input date string to a date format and then
I'm trying to convert date formats in javascript. I get a string from a
I'm trying to convert a string from to a Joda DateTime object. The date
I'm trying to convert a string date value from a submitted form into an
I am trying to convert a date from yyyy-mm-dd to dd-mm-yyyy (but not in
I am trying to convert a date value of YYYY/MM/DD from a textbox to
i am trying to convert a date string to date format >>> str =
I am trying to convert an string date to a NSDate to make some
I am trying to convert java.util.Date into string as Twenty Sixth of October Nineteen
I'm trying to convert string to date format.I trying lot of ways to do

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.