18 digit timestamp?
Asked Answered
G

5

6

I am working on a system related to tv recordings.

I am parsing the following xml from another system (to which i have no documentation):

<Program FileName="2009.11.07-Saturday 07 November 2009.dvr-ms" SubChannel="ABC1" StartTime="633931722046825183" StopTime="633932388000119414" ActualStopTime="633932388016825183" ShareShow="True" />
<Program FileName="2009.11.08-Sunday 08 November 2009.dvr-ms" SubChannel="ABC1" StartTime="633932586046773253" StopTime="633933252000157907" ActualStopTime="633933252006773253" ShareShow="True" />
<Program FileName="2009.11.09-Monday 09 November 2009.dvr-ms" SubChannel="ABC1" StartTime="633933450046168953" StopTime="633934116000207688" ActualStopTime="633934116026168953" ShareShow="True" />
<Program FileName="2009.11.10-Tuesday 10 November 2009.dvr-ms" SubChannel="ABC1" StartTime="633934314046899495" StopTime="633934980000869533" ActualStopTime="633934980096899495" ShareShow="True" />
<Program FileName="2009.11.11-Wednesday 11 November 2009.dvr-ms" SubChannel="ABC1" StartTime="633935178054202612" StopTime="633935844000077447" ActualStopTime="633935844064202612" ShareShow="True" />
<Program FileName="2009.11.12-Thursday 12 November 2009.dvr-ms" SubChannel="ABC1" StartTime="633936042047633656" StopTime="633936708000009191" ActualStopTime="633936708047633656" ShareShow="True" />

My question is, does anyone recognise the timestamp format of the StartTime and StopTime attributes? I thought typically timestamps to the second had 10 digits, so where are the other 8 coming from? My guess is something like timezone and millisecond accuracy.

I am using php, so a php specific way of converting it to a datetime would be nice, but anything is good.

Gondar answered 2/12, 2009 at 12:50 Comment(1)
Timestamps counting milliseconds from epoch currently have 10 digits. Once there were 3/4/5/6/etc digits to a "now" timestamp.Najera
E
16

It looks like C#'s DateTime ticks:

The DateTime value type represents dates and times with values ranging from 12:00:00 midnight, January 1, 0001 Anno Domini (Common Era) through 11:59:59 P.M., December 31, 9999 A.D. (C.E.)

This line:

Console.WriteLine (new DateTime (633936042047633656));

prints:

11/12/2009 6:30:04 AM

If you need to convert from those numbers to Unix time, substract 621355968000000000L, which is the Unix epoch expressed in ticks.

Emmanuel answered 2/12, 2009 at 12:59 Comment(2)
Hmm, with no 64 bit int in PHP that could be an issue :P Oh well, i'll find a way.Gondar
Shouldn't be too hard to do that math in 32 bits, with a bit of string preprocessing. First "divide" by a million by removing the last 6 characters of the string, then remove the leading "6". Next subtract 2 from the first digit of the string. Now convert what's left to a 32 bits integer, and subtract 1355968000.Lonnie
H
2

With the gmp lib installed in php you can do it like this:

$epoch     = '621355968000000000';
$newtime   = gmp_sub($dateTime, $epoch);
$newtime   = gmp_div($newtime, '10000000');
$timestamp = gmp_strval($newtime);

and now you got a date:

echo date('Y-m-d H:i:s', $timestamp);
Helpmeet answered 2/12, 2009 at 15:1 Comment(0)
C
1
$dateLargeInt= "131424999530821857";
$secsAfterADEpoch = $dateLargeInt / (10000000); 
$ADToUnixConvertor=((1970-1601) * 365.242190) * 86400;
// unix epoch - AD epoch * number of tropical days * seconds in a day 
$unixTsLastLogon=intval($secsAfterADEpoch-$ADToUnixConvertor); 

// unix Timestamp version of AD timestamp
$lastlogon=date("d-m-Y", $unixTsLastLogon); // formatted date

echo $lastlogon;
Cleveland answered 29/6, 2017 at 10:47 Comment(0)
D
0
date_default_timezone_set('UTC');

echo date("Y-m-d H:i:s", (strtotime("01/01/0001 00:00:00 UTC") + (634019142119225390 / 10000000)));

simple but works

Diondione answered 10/3, 2022 at 13:19 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Doelling
D
-1
const fmtTime = (dateLargeInt: number) => {
    const ADToUnixConvertor = ((1970 - 1601) * 365.242190) * 86400;
    const unixTsLastLogon = Math.floor(dateLargeInt / 10000000 - ADToUnixConvertor);
    return dayjs(new Date(unixTsLastLogon * 1000)).format("YYYY/MM/DD HH:mm");
}
Deville answered 31/7 at 5:42 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Doelling

© 2022 - 2024 — McMap. All rights reserved.