Domanda

I am writing a script in PHP which will convert Numbers file into HTML table, but I can not figure out which format is used for date storage. The date cell tag looks like

<sf:d 
    sf:s="SFTCellStyle-128" 
    sf:w="84.074219" 
    sf:h="14" 
    sf:cell-date="371397519.99999952" />

so the date must be in sf:cell-date attribute, but I can not figure out how to convert it into human readable format. Any ideas? I have never seen date value as float number.

È stato utile?

Soluzione

As written in a comment, it is the number of seconds since 01/01/2001 at 00:00:00. Equipped with that knowledge and because this goes hand in hand with the UNIX Epoch all you need to do is to define and use the offset. It should be compatible with nearly every of the existing PHP date functions and objects, for example with date:

define('CELL_DATE_EPOCH_OFFSET', 978307200);

$sf_cell_date = 371397519.99999952;

echo date('r', CELL_DATE_EPOCH_OFFSET + $sf_cell_date);

The output of this little script is (in my timezone):

Mon, 08 Oct 2012 15:58:39 +0200

I hope this is helpful. 978307200 is the unix timestamp for 01/01/2001 00:00:00 UTC, you can get with PHP for example with the following code-example:

$base = new DateTime('01/01/2001 00:00:00 UTC');

echo $base->getTimestamp(), "\n";

in case that was your problem.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top