6

I m getting start time 634942626000000000 and end time 634942638000000000. How can I convert it to a Unix timestamp? I want to display formatted date/time in PHP?

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Ricky Watson
  • 133
  • 1
  • 4
  • 15

3 Answers3

10

C# ticks is a number of ticks since midnight 0001-01-01 00:00:00 (every tick is 1/10000000 of second) and UNIX timestamp is number of seconds since beginning of the UNIX epoch (1970-01-01 01:00:00), so desired result is $seconds = 634942626000000000/10000000 - $number_of_seconds, where $number_of_seconds is seconds between 0001-00-01 00:00:00 and 1970-01-01 01:00:00. So, all you need now is to determine what $number_of_seconds is equals.

Update: this is how to do it in C# : How to convert a Unix timestamp to DateTime and vice versa?

Update 2 Using this simple script http://hastebin.com/lefiyiheju.mel determined that $number_of_seconds is 62136892800, but I don't know if it is much accurate

Community
  • 1
  • 1
Timur
  • 6,668
  • 1
  • 28
  • 37
  • 6.214×10^10 seconds is the result wolfram alpha gives. for number of seconds between 0001 and 1970 however that is not accurate enough for the kind of calculation he is looking for. – WhyteWolf Jan 20 '13 at 18:46
  • May be this can be done using C# + bigint, because it calculates time from `0001-01-01 00:00:00` everywhere, but I don't know C# language – Timur Jan 20 '13 at 18:49
  • Thanks a lot for detail reply..I really appreciate it. – Ricky Watson Jan 21 '13 at 15:33
  • I've calculated $number_of_seconds = 62135600400. And this seems to be accurate up to seconds, which is good enough for what I want to use it for. – mozey Oct 16 '15 at 10:12
  • 2
    `Math.floor(numOfTicks/10000 - 62136892800000)` // JS timestamp (ms) `new Date(Math.floor(numOfTicks/10000 - 62136892800000))` // js Date – Alireza Mirian Jan 16 '18 at 06:18
  • 1
    Isn't your UNIX epoch off by 1 hour? from what i found, Unix Timestamp 0 is equal to: 621355968000000000 Ticks. Shouldn't $num_of_secs be 621355968000000000/10000000 ? – Sinkeat Apr 19 '21 at 04:10
1

This should do it:

$seconds = 634942626000000000 / 1000000000;
echo date("Y-m-d H:i:s", $seconds);
John Conde
  • 217,595
  • 99
  • 455
  • 496
0

In Python, you'll do

In [53]: import datetime

In [54]: ticks = 634942626000000000

In [55]: start = datetime.datetime(1, 1, 1)

In [56]: delta = datetime.timedelta(seconds=ticks/10000000)

In [57]: the_actual_date = start + delta

In [58]: the_actual_date.timestamp()
Out[58]: 1358665800.0

In [59]: the_actual_date
Out[59]: datetime.datetime(2013, 1, 20, 7, 10)
Lucianovici
  • 314
  • 3
  • 9