1

I am trying to convert to Julian Time Stamp to Date Time. I have the following microseconds time stamp 212302469304212709. As i understand i need to add these milliseconds to the beginning of Julian Calendar (January 1, 4713 B.C., 12:00 (noon)). So i have the following method:

private DateTime GetDateTime(string julianTimeStamp)
{
   var julianMilliseconds = Convert.ToDouble(julianTimeStamp)/1000;

   var beginningOfTimes = new DateTime(1, 1, 1, 0, 0, 0, 0);

   var dateTime = beginningOfTimes.AddMilliseconds(julianMilliseconds).AddYears(-4713).AddMonths(-1).AddDays(-1).AddHours(-12);

   return dateTime;
}

Assume i pass 212302469304212709 string as the parameter. The expected result should be 2015/07(July)/01 00:08:24.212. Based on my method, i have almost the same result, but day is not 1, it is 6. Same problem for different time stamps i tested. Could any one tell me what i am doing wrong? Thanks in advance.

Edited: This is the exact date time i expect to receive: 2015(year) 7(month) 1(day) 0(hour) 8(minute) 24(second) 212(millisecond) 709(microsecond)

Eugene
  • 365
  • 6
  • 21
  • 1
    calendars are an absolute mess. particularly ancient ones. What you mean by a julian calendar varies depending on where you are in the world. Wikipedia disputes your 'zero' date for a Julian calendar, etc. Do you know what day today is in the Julian calendar? really? Which country? Which version? I say these things not to be difficult and unhelpful but to highlight the problem. You need to know EXACTLY what your timestamp represents to hope to be able to convert it. – Stewart_R Jul 30 '15 at 21:20
  • Hi Stewart_R, based on my specs the Julian Calendar starts on January 1, 4713 B.C., 12:00 (noon). I have edited the question and included the exact date time i am expecting from the example above. Thanks for your note. – Eugene Jul 30 '15 at 22:03
  • 1
    The Julian calendar starts on Jan 1 4713 BC??? Which country/timezone? Which version of the Julian Calendar (there is not one universal version)? How does the calendar your timestamp uses deal with the leap year controversy: https://en.wikipedia.org/wiki/Julian_calendar#Leap_year_error Since your expected value is presumably a Gregorian date, how did you calculate the difference? There were many ways to convert depending on context/country: https://en.wikipedia.org/wiki/Julian_calendar#From_Julian_to_Gregorian – Stewart_R Jul 31 '15 at 06:21
  • 1
    To be more practical: if you already know that 21202469304212709 should equal 1st july 2015 - why not just use THIS as the zero date? Then add time for later and subtract for earlier? Then so long as you stay out of history and stay in the same timezone you should be ok? Otherwise there are nuances to the context of your question we dont know/ – Stewart_R Jul 31 '15 at 06:24
  • 1
    @Stewart_R: This terminology is confusing, generally. People tend to use "Julian Date" and "Julian Day Number" interchangeably when in fact they may be very different things. A "Julian Date" can be two things. It can be a date reckoned on the Julian Calendar (which predated the Gregorian Reform in the 16th century) ... or ... it can be a continuous count of days since Noon Jan 1, 4713 BC (also known as a Julian Day Number). Only by context can one know what a "Julian Date" really is (Julian Calendar vs Julian Day Number). – scottb Aug 15 '15 at 04:41
  • @Eugene: answers in this post may be helpful to you: http://stackoverflow.com/questions/32016368/convert-a-julian-date-to-an-instant/32017765#32017765 – scottb Aug 15 '15 at 04:44

2 Answers2

2

DateTime uses Gregorian calendar, so when you substract years, months and so on you are doing it with that calendar, not the Julian.

Unfortunately DateTime does not support dates before year 1. You can check the library in this post, maybe it helps you.

Community
  • 1
  • 1
Martín Misol
  • 333
  • 1
  • 7
2

The given timestamp 212,302,469,304,212,709 μs when converted to days (just divide by 86,400,000,000) gives 2457204.505836 days (to six decimal places, which is the best I can do without a lot of extra trouble). Using the Multi Year Computer Interactive Almanac (MICA) written by the United States Naval Observatory, and putting in the free form date 2015(year) 7(month) 1(day) 0(hour) 8(minute) 24(second) 212(millisecond) 709(microsecond), the program calculates exactly the same day count (to six decimal places), proving the time stamp is an accurate Julian date.

One problem with the OP's calculation is trying to use the DateTime class before the earliest supported date, as pointed out by another poster. Also, the OP didn't say if 1 July 2015 was in the Julian or Gregorian calendar, but the MICA calculation proves it is in the Gregorian calendar. Since the OP is working in the Gregorian calendar, the epoch of Julian dates should be stated in the Gregorian proleptic calendar: Noon Universal Time, November 24, 4714 BC. The oft-quoted date January 1, 4713 BC is a proleptic Julian calendar date.

"Proleptic" means a date has been found by beginning at a modern date, who's calendar date is known with absolute certainty, and applying the rules of the chosen calendar backward until the desired date is reached, even though the desired date is before the chosen calendar was invented.

Gerard Ashton
  • 560
  • 4
  • 16
  • Thanks a lot Gerard! I got my mistake and based on your answer i solved my problem. – Eugene Jul 31 '15 at 20:17
  • Very interesting. How did you get from the Julian date `January 1, 4713 BC` to the Gregorian `Noon Universal Time, November 24, 4714 BC`? Also, when I do the calculation on a site like [this] (http://www.math.harvard.edu/computing/javascript/Calendar/) with Julian Day of 0, it comes out to `4713`, not `4714` – mkobit Sep 08 '15 at 18:11
  • mkobit used Fourmilab, which uses a bizzare year numbering convention, along with Dershowitz and Reingold. These guys think, for the Gregorian calendar, 1 BC = 0, but for Julian calendar, 1 BC =-1. Using different meanings for negative years depending on whether it is the Julian or Gregorian calendar seems nuts to me. – Gerard Ashton Sep 09 '15 at 18:41
  • "How did you get from the Julian date January 1, 4713 BC to the Gregorian Noon Universal Time, November 24, 4714 BC?" I looked it up in Dershowitz and Reingold, "Calendrical Calculations" (2008), page 15. – Gerard Ashton Sep 09 '15 at 19:03