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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:04:02+00:00 2026-06-10T05:04:02+00:00

I am not interested in what the current UTC time is in milliseconds, nor

  • 0

I am not interested in what the current UTC time is in milliseconds, nor do I need to mess with timezones. My original date is already stored as a UTC timestamp.

I have a date stored in a database in UTC time, “2012-06-14 05:01:25”.
I am not interested in the datetime, but just the date portion of the it. So, after retrieving the date in Java, and excluding the hours, minutes, and seconds – I am left with “2012-06-14”.

How can I convert this into UTC milliseconds?

  • 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-10T05:04:03+00:00Added an answer on June 10, 2026 at 5:04 am

    EDIT: I’d missed the “ignoring the time of day” part. It’s now present, but near the end…

    The simplest approach is probably to use SimpleDateFormat, having set the time zone appropriately:

    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US);
    format.setTimeZone(TimeZone.getTimeZone("UTC"));
    
    Date date = format.parse(text);
    long millis = date.getTime();
    

    (Setting the time zone is the important bit here, as otherwise it will interpret the value to be in the local time zone.)

    Alternatively, if you’re doing anything less trivial than this, use Joda Time which is a much better date/time API. In particular, SimpleDateFormat isn’t thread-safe whereas DateTimeFormatter is:

    // This can be reused freely across threads after construction.
    DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss")
        .withLocale(Locale.US)
        .withZoneUTC();
    
    // Option 1
    DateTime datetime = formatter.parseDateTime(text);
    long millis = dateTime.getMillis();
    
    // Option 2, more direct, but harder to diagnose errors
    long millis = formatter.parseMillis(text);
    

    Now so far, we’ve parsed the whole whole caboodle. The easiest way of ignoring the date part is just to round it off – after all, Java doesn’t observe leap seconds, so we can just truncate it:

    long millisPerDay = 24L * 60L * 60L * 1000L; // Or use TimeUnit
    long dayMillis = (millis / millisPerDay) * millisPerDay;
    

    That will “round towards 1970” so if you have a date before 1970 it will round to the end of the day – but I suspect that’s unlikely to be a problem.

    With the Joda Time version you could just use this instead:

    DateTime dateTime = formatter.parseDateTime(text);
    long millis = dateTime.toLocalDate().getLocalMillis();
    

    I would personally not go with the idea of just taking a substring. Even though you’re not actually interested in preserving the hour/minute/second, I think it’s appropriate to parse what you’ve been given and then throw away information. Aside from anything else, it makes your code fail appropriately with bad data, e.g.

    "2012-06-100"
    

    or

    "2012-06-14 25:01:25"
    

    indicate problems in whatever’s supplying you data, and it’s good to spot that rather than to continue blindly just because the first 10 characters are okay.

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

Sidebar

Related Questions

I'm not interested in warming up the Python 2 or Python 3? questions (even
I am not interested in any auto update solution, such as ClickOnce or the
I'm not interested in call or apply to change the this reference. Just for
I have the following package on Eclipse: com.mortgageapp.projects.app I'm not interested about the package
I am looking for a data access layer for ado.net. I am not interested
I am currently researching RIA services with Silverlight. We are not interested in using
Like with attribute disable on the <input> html tag. I'm not interested in the
I'm interested in doing some Java web development but I'm not really interested in
I am interested in parsing regexes (not to be confused with using regexes for
I'm interested in using the WMD editor in another project * but I'm not

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.