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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:10:26+00:00 2026-06-15T15:10:26+00:00

I am trying to format some dates using the Java Date class. I have

  • 0

I am trying to format some dates using the Java Date class. I have some long values that I have gotten through previous calculations. Before I start formatting any dates I have a list of longs, they are as follows.

-12345
0
12345

I do some basic formatting like this…

 DateFormat df = new SimpleDateFormat("dd/MMM/yyyy HH:mm:ss");
 String formattedDate = df.format(new Date(dateNumber.longValue())); 

Because Java uses the start of 1970 as a base my expected output would be something like

31/Dec/1969 23:59:47
01/Jan/1970 00:00:00
01/Jan/1970 00:00:12

However the output I am actually getting is

31/Dec/1969 18:59:47
31/Dec/1969 19:00:00
31/Dec/1969 19:00:12

I am a bit confused as to why they are all on December the 31 rather than split between December 31 and January 1. Due to the face that the second two numbers in the list are positive I cannot figure out why the date would be anything before 1970. If anyone can help me out with this using basic Java libraries I’d much appreciate it.

  • 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-15T15:10:27+00:00Added an answer on June 15, 2026 at 3:10 pm

    You can set the timeZone of data format object to GMT:

    df.setTimeZone(TimeZone.getTimeZone("GMT"));
    

    and you should get what you wanted. The timestamp represents “number of milliseconds since January 1, 1970, 00:00:00 GMT” and for your current timezone the results will differ.

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

Sidebar

Related Questions

I have a list of dates and values in the format: {{{dateInfo1},value1},{{dateInfo2},value2},...,{{dateInfoN},valueN}} With some
I am trying to convert a string to proper date format using Java's SimpleDateFormat
I have been trying to format regional (locale) specific numbers, dates etc using Jquery.
I am trying to format some html output from my db using php and
I am trying to format some c# output so that a number always has
I'm trying to sanitize/format some input using regex for a mixed latin/ideographic(chinese/japanse/korean) full text
I need some help trying to figure out how to format dates in perl.
I'm using Zend_Db to query a table. I have some WHERE clauses that need
I have converted some dates to string and stored them in my database using
I'm trying to format some dates in PHP (i'm a Coldfusion programmer, so 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.