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?
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
0001-01-01 00:00:00
everywhere, but I don't know C# language –
Finger Math.floor(numOfTicks/10000 - 62136892800000)
// JS timestamp (ms) new Date(Math.floor(numOfTicks/10000 - 62136892800000))
// js Date –
Stipitate DateTime.UnixEpoch.Ticks == 621355968000000000
. –
Cracow This should do it:
$seconds = 634942626000000000 / 1000000000;
echo date("Y-m-d H:i:s", $seconds);
@Sinkeat had the right answer in the comments for https://mcmap.net/q/1467539/-convert-ticks-to-unix-timestamp.
Console.WriteLine($"{DateTime.UnixEpoch}: {DateTime.UnixEpoch.Ticks}");
prints 1/1/1970 12:00:00 AM: 621355968000000000
. So
$number_of_seconds = 62135596800
$seconds = $ticks/10000000 - $number_of_seconds
should do it. I don't have a PHP interpreter up to test this, but a similar formula in Google Sheets does work with the above numbers, e.g.
=EPOCHTODATE(C2/10000000-62135596800)
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)
© 2022 - 2024 — McMap. All rights reserved.