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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T16:01:20+00:00 2026-05-21T16:01:20+00:00

I have the following code that takes a String of milliseconds (will be from

  • 0

I have the following code that takes a String of milliseconds (will be from an RSS feed so will be a String, the example below is a quick test program) and converts those millis into a Date object.

public static void main(String[] args) {
    String ms = "1302805253";
    SimpleDateFormat dateFormatter = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz");
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(Long.parseLong(ms));

    try {
        String dateFormat = dateFormatter.format(calendar.getTime());
        System.out.println("Date Format = " + dateFormat);

        Date dateParse = dateFormatter.parse(dateFormatter.format(calendar.getTime()));
        System.out.println("Date Parse  = " + dateParse);
    } catch (ParseException e) {
        // TODO: handle exception
    }
}


Output:
    Date Format = Fri, 16 Jan 1970 02:53:25 GMT
    Date Parse  = Fri Jan 16 03:53:25 GMT 1970

As you can see, between the formatting of the calendar object and parsing of the resulting String, an hour is being lost. Also, the formatting of the output has changed. Can anyone help me as to why this is happening, and how to get around it? I want the Date object to be the same format as the “Date Format” output.

  • 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-21T16:01:21+00:00Added an answer on May 21, 2026 at 4:01 pm

    I believe it’s happening because the UK didn’t actually use GMT in 1970, and Java has a bug around that… it will format a date in 1970 as if the UK were using GMT, but without actually changing the offset. Simple example:

    Date date = new Date(0);
    SimpleDateFormat sdf = new SimpleDateFormat("dd MMM yyyy HH:mm:ss zzz");
    sdf.setTimeZone(TimeZone.getTimeZone("Europe/London"));
    System.out.println(sdf.format(date));
    

    Result:

    01 Jan 1970 01:00:00 GMT
    

    Note that it claims it’s 1am GMT… which is incorrect. It was 1am in Europe/London time, but Europe/London wasn’t observing GMT.

    Joda Time gets this right in that it prints out BST – but Joda Time doesn’t like parsing values with time zone abbreviations. However, you can get it to use time zone offets instead:

    import org.joda.time.*;
    import org.joda.time.format.*;
    
    public class Test {
        public static void main(String[] args) throws Exception {
            DateTime date = new DateTime(0, DateTimeZone.forID("Europe/London"));
    
            DateTimeFormatter formatter = DateTimeFormat.forPattern(
                "dd MMM yyyy HH:mm:ss Z");
    
            String text = formatter.print(date); // 01 Jan 1970 01:00:00 +0100
            System.out.println(text);
    
            DateTime parsed = formatter.parseDateTime(text);
            System.out.println(parsed.equals(date)); // true
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a NSMutableAttributedString, I need to take substring from it.I use the following
I have a code in which the character array is populated by integers (converted
I have run into a rather weird problem. I have created the following query
I had a bug that caused an integer overflow, resulting in wrong (negative) timestamps
I have used Cell.ContentView in my implementation for customizing the cell contents. It works
I want to convert local html file on iPhone to PDF document. I have
In some Java code running on Windows, I'm reading some large blocks of RGB
I'm trying to take an ADO Recordset and then loop through it to parse
After taking some small courses and using WPF and C# a bit I've decided
I am programming a very simple application to store results of soccer matches, and

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.