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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T04:40:26+00:00 2026-05-21T04:40:26+00:00

All, I am working with a binary specification whose TimeStamp fields are defined as

  • 0

All,

I am working with a binary specification whose TimeStamp fields are defined as “Milliseconds since January 1, 2000 UTC time”. I am doing the following calculation:

public static final TimeZone UTC = TimeZone.getTimeZone("UTC") ;
public static final Calendar Y2K_EPOCH = Calendar.getInstance(UTC);
static {
    Y2K_EPOCH.clear();
    // Month is 0 based; day is 1 based.  Reset time to be first second of January 1, 2000
    Y2K_EPOCH.set(2000, 0, 1, 0, 0, 0);
}
public static final long MS_BETWEEN_ORIGINAL_EPOCH_AND_Y2K_EPOCH = Y2K_EPOCH.getTimeInMillis();

public static long getMillisecondsSinceY2K(Date date) {
    long time = date.getTime();
    if (time < MS_BETWEEN_ORIGINAL_EPOCH_AND_Y2K_EPOCH) {
        throw new IllegalArgumentException("Date must occur after January 1, 2000");
    }
    return time - MS_BETWEEN_ORIGINAL_EPOCH_AND_Y2K_EPOCH;
}

My question is, is this the correct way to do the conversion between standard Java Date objects and this datatype? Is there a better way of doing this? I know about Joda time but I’d rather not bring that external dependency in if I can help 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-05-21T04:40:26+00:00Added an answer on May 21, 2026 at 4:40 am

    Time is a tricky mess, especially UTC time. Assuming you want a pretty good time based of an arbitrary epoch, a simple subtraction like what you do should be fine. If you are worried about leap-seconds precision I would highly suggest you use Joda or some reliable external library.

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

Sidebar

Related Questions

I'm working on a .Net applications with multiple threads doing all sorts of things.
I'm trying to write a 2d array into an output file, it's all working
My web service (wcf) stopped working all of a sudden. I compared my web.config
My day job includes working to develop a Pascal-like compiler. I've been working all
One long term project I have is working through all the exercises of SICP.
I'm trying to layer some elements using z-index and it's not working at all.
All, I'm working on a SharePoint project, but this isn't a SharePoint-specific question per-se.
I'm working on a C#/ASP.NET project that has all the javascript files in a
We are working on standardizing our Bugzilla application across all projects. The default installation
I'm working on a Silverlight Project with all the features and limitations that entails.

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.