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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:22:56+00:00 2026-05-16T01:22:56+00:00

I want to get the UTC time for 01/01/2100 in Java to ‘2100-01-01 00:00:00’.

  • 0

I want to get the UTC time for 01/01/2100 in Java to ‘2100-01-01 00:00:00’. I am getting “2100-01-01 00:08:00”. Any idea, how to correct this.

public Date getFinalTime() {
    Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC"));

    DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
    Date finalTime = null;

    try
    {
        finalTime = df.parse("01/01/2100");            
    } catch (ParseException e)
    {
        e.printStackTrace();
    }

    calendar.setTime(finalTime);
    return calendar.getTime();
}
  • 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-16T01:22:57+00:00Added an answer on May 16, 2026 at 1:22 am

    You need to specify the time zone for the SimpleDateFormat as well – currently that’s parsing midnight local time which is ending up as 8am UTC.

    TimeZone utc = TimeZone.getTimeZone("UTC");
    Calendar calendar = Calendar.getInstance(utc);
    
    DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
    df.setTimeZone(utc);
    Date finalTime = null;
    
    try
    {
        finalTime = df.parse("01/01/2100");            
    } catch (ParseException e)
    {
        e.printStackTrace();
    }
    
    calendar.setTime(finalTime);
    

    As ever though, I would personally recommend using Joda Time which is far more capable in general. I’d be happy to translate your example into Joda Time if you want.

    Additionally, I see you’re returning calendar.getTime() – that’s just the same as returning finalTime as soon as you’ve computed it.

    Finally, just catching a ParseException and carrying on as if it didn’t happen is a very bad idea. I’m hoping this is just sample code and it doesn’t reflect your real method. Likewise I’m assuming that really you’ll be parsing some other text – if you’re not, then as Eyal said, you should just call methods on Calendar directly. (Or, again, use Joda Time.)

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

Sidebar

Related Questions

I want to get the current UTC date with Javascript. How can I do
I get the UTC Date and Time using: Dim UTCN As Date = (Date.UtcNow)
I want to get the modification date of a file in UTC from Python.
I want to get the time at UTC or GMT with respect to the
I want to get a date and time in the form of 1/1/2000. The
I want get the time used for a case so I can create an
I want to get 100 and example from this string ?connect:100/username:example/ I searched in
How do I get the UTC time in milliseconds under the Windows platform? I
I need to get the UTC offset of the current time zone in Perl
how can I get the time difference from the string below, I want to

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.