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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:19:51+00:00 2026-05-23T09:19:51+00:00

I want to get the current time and date in milliseconds. How can I

  • 0

I want to get the current time and date in milliseconds. How can I get this?

I tried this:

Date date=new Date() ;  
System.out.println("Today is " +date.getTime());

It will return the milliseconds from the 1 Jan 1970.

But I want the current millisecods of the today’s date, like:

23:59:00 = 86340000 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-05-23T09:19:52+00:00Added an answer on May 23, 2026 at 9:19 am

    This is not the correct approach for Java 8 or newer. This answer is retained for posterity; for any reasonably modern Java use Basil Bourque’s approach instead.


    The following seems to work.

    Calendar rightNow = Calendar.getInstance();
    
    // offset to add since we're not UTC
    long offset = rightNow.get(Calendar.ZONE_OFFSET) +
        rightNow.get(Calendar.DST_OFFSET);
    long sinceMidnight = (rightNow.getTimeInMillis() + offset) %
        (24 * 60 * 60 * 1000);
    
    System.out.println(sinceMidnight + " milliseconds since midnight");
    

    The problem is that date.getTime() returns the number of milliseconds from 1970-01-01T00:00:00Z, but new Date() gives the current local time. Adding the ZONE_OFFSET and DST_OFFSET from the Calendar class gives you the time in the default/current time zone.

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

Sidebar

Related Questions

I want to store the current date & time which can be get by
I get the current time with SimpleDateFormat and I want to return new time
Not sure if I can do it this way. I want to get current
I want to get the current UTC date with Javascript. How can I do
I want to get the current date (day, mon and year). I found out
I am having a quite annoying problem. I want to get the current date/time
I would like to get the current Date/Time in actionscript 3, and I want
I would like to get the current date with the time zeroed out in
2011-03-04 21:00:40 I want to get current date and time in the above format.
I know how to get the current date and time in mfc.but I want

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.