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

The Archive Base Latest Questions

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

I have a variable containing the days since the epoch reference date of 1970-01-01

  • 0

I have a variable containing the days since the epoch reference date of 1970-01-01 for a certain date.

Does someone know the way to convert this variable to a java.util.Calendar?

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

    The following should work:

    Calendar c = new GregorianCalendar();
    c.setTime(new Date(0));
    
    c.add(Calendar.DAY_OF_YEAR, 1000);
    
    System.err.println(c.getTime());
    

    A note regarding time zones:

    A new GregorianCalendar instance is created using the default time zone of the system the program is running on. Since Epoch is relative to UTC (GMT in Java) any time zone different from UTC must be handled with care. The following program illustrates the problem:

    TimeZone.setDefault(TimeZone.getTimeZone("GMT-1"));
    
    Calendar c = new GregorianCalendar();
    c.setTimeInMillis(0);
    
    System.err.println(c.getTime());
    System.err.println(c.get(Calendar.DAY_OF_YEAR));
    
    c.add(Calendar.DAY_OF_YEAR, 1);
    System.err.println(c.getTime());
    System.err.println(c.get(Calendar.DAY_OF_YEAR));
    

    This prints

    Wed Dec 31 23:00:00 GMT-01:00 1969
    365
    Thu Jan 01 23:00:00 GMT-01:00 1970
    1
    

    This demonstrates that it is not enough to use e.g. c.get(Calendar.DAY_OF_YEAR). In this case one must always take into account what time of day it is. This can be avoided by using GMT explicitly when creating the GregorianCalendar: new GregorianCalendar(TimeZone.getTimeZone("GMT")). If the calendar is created such, the output is:

    Wed Dec 31 23:00:00 GMT-01:00 1969
    1
    Thu Jan 01 23:00:00 GMT-01:00 1970
    2
    

    Now the calendar returns useful values. The reason why the Date returned by c.getTime() is still “off” is that the toString() method uses the default TimeZone to build the string. At the top we set this to GMT-1 so everything is normal.

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

Sidebar

Related Questions

so I have a variable containing a date object. I want to convert it
I have a variable called $effectiveDate containing the date 2012-03-26 . I am trying
let's say I have a variable containing an integer or a float (since integers
If I have a variable containing a string, is there a way that I
What's the best way to achieve the following: I have a $img variable containing
If I have a variable containing an unescaped dollar sign, is there any way
I have a variable containing a string. The string can come in several ways:
Possible Duplicate: Place commas in Javascript integers I have a variable containing a number
Suppose I have a class Foo , with a private variable bar_ containing some
i have variable $lang which convert string to the selected language but i am

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.