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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:18:24+00:00 2026-06-10T07:18:24+00:00

If I write a simple method to return the milliseconds between epoch time and

  • 0

If I write a simple method to return the milliseconds between epoch time and DateTime.UtcNow, I get a proper answer. However, if I write a method to return the milliseconds between some arbitrary date and epoch time, the last three digits are always zero. ‘Some arbitrary date’ means that I pass in to the method the output of DateTime.Parse(“arbitrary date string”). As near as I can make out, the DateTime object returned by .Parse is not returning all the significant digits.

Test method:

    static void GetMillis()
        {
            DateTime dUtc = DateTime.UtcNow;
            DateTime epoch = new DateTime(1970,1,1,0,0,0,DateTimeKind.Utc);
            double utcmillis = (dUtc - epoch).TotalMilliseconds;
            String timestamp = dUtc.ToString();
            DateTime arbitrary = (DateTime.Parse(timestamp));
            Console.WriteLine("Milliseconds between DateTime.UtcNow {0} \nand epoch time {1} are {2}", dUtc, epoch, utcmillis);
            Console.WriteLine("Milliseconds between arbitrary date {0} \nand epoch time {1} are {2}", arbitrary, epoch, (arbitrary - epoch).TotalMilliseconds);
        }

Output:

C:\src\vs\epochConverter\epochConverter\bin\Debug
{powem} [54] --> .\epochConverter.exe -debug
Milliseconds between DateTime.UtcNow 8/26/2012 11:12:31 PM
and epoch time 1/1/1970 12:00:00 AM are 1346022751385.8
Milliseconds between arbitrary date 8/26/2012 11:12:31 PM
and epoch time 1/1/1970 12:00:00 AM are 1346022751000

I don’t know if I’m doing something grotesquely wrong or not understanding the math here. I’ve researched in MSDN and can’t find anything relating to this difference. I really would like to be able to compute the millis as described — is it possible?

Thanks.

mp

  • 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-10T07:18:25+00:00Added an answer on June 10, 2026 at 7:18 am

    You want to examine the intermediate values of:

    String timestamp = dUtc.ToString();
    

    Just what it returns will depend on your local settings, but it’ll be something like 8/26/2012 11:12:31, which is only accurate to the nearest second.

    Parsing that of course gives a date-time with 0 milliseconds.

    It is therefore correct that your milliseconds-since-epoch method has zeros at that point.

    If however you did something like:

    arbitrary = new DateTime(2012, 8, 26, 11, 12, 31, 123);
    

    You’d get those 123 milliseconds influencing the result. You can also use a ToString and a ParseExact that includes fractions of a second, or a whole slew of other ways of obtaining a DateTime.

    In all, your milliseconds-since-epoch worked perfectly, but your way of getting a date to test it was flawed.

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

Sidebar

Related Questions

I write a simple application to get phone number in Contacts. However, the phone
I am trying to write a very simple method to remove duplicates in a
Hi I'm trying to write a piece of code for a simple verification method
I'm trying to write simple proxy server for some purpose. In it I use
I was trying to write a simple method: boolean validate(MyObject o) { // propertyA
I'm trying to write a simple utility method for adding aninteger number of days
I need to write a simple ping method in Cocoa/Objective-C. It also needs to
I'm attempting to write a simple Select method on a class that inherits from
I'm trying to write a fairly simple application that passes data between two sockets.
I am trying to write a method to return an instance of itself. The

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.