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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T19:57:33+00:00 2026-05-16T19:57:33+00:00

I have a String, representing time in UTC. I need to convert it to

  • 0

I have a String, representing time in UTC.
I need to convert it to long representing milliseconds since midnight at EST, considering daylight saving times.
For example, in January, the offset is 5 hours, but in June 4 hours.

However, the code below displays the same offset of 5 hours for both June and January.
The variable tzOffset = -18000000 (=-5 hours), regardless the date month.

Please advise,

Thanks!

package TimeConversion;

import java.text.SimpleDateFormat;

import java.util.*;

public class TimeConversion {

    public static void main(String[] args) throws Exception {

        String utcTime = "20100101120000000";
        SimpleDateFormat sdfIn = new SimpleDateFormat("yyyyMMddHHmmssSSS");
        sdfIn.setTimeZone(TimeZone.getTimeZone("UTC"));        
        long utcMillis = sdfIn.parse(utcTime).getTime();
        long tzOffset = TimeZone.getTimeZone("EST").getOffset(utcMillis);
        long estMillis = utcMillis + tzOffset;
        long estMillisSinceMidnight = estMillis % 86400000;
        System.out.println("utcTime = " + utcTime + "\nestMillisSinceMidnight = " + estMillisSinceMidnight + "(" + 24.0 * estMillisSinceMidnight / 86.4e6 + ")");
    }

}
  • 1 1 Answer
  • 2 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-16T19:57:33+00:00Added an answer on May 16, 2026 at 7:57 pm

    You could steal some code from this calendar conversion utility. What you probably need is getLocalTime. Disclaimer: I wrote it.

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

Sidebar

Related Questions

In Java I have a long integer representing a period of time in milliseconds.
I have a string representing a path. Because this application is used on Windows,
In an ASP.NET 2.0 website, I have a string representing some well-formed XML. I
I have an HTML string representing an element: '<li>text</li>' . I'd like to append
I have a String representation of a date that I need to create a
My web app stores all timestamps in UTC without time zones. I have a
I am receiving data representing a time slot from a service as a string
I have string like this /c SomeText\MoreText Some Text\More Text\Lol SomeText I want to
I have string that I want to chop to array of substrings of given
Imagine I have String in C#: I Don’t see ya.. I want to remove

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.