Search code examples
pythondate

Python date format?


I'm really hoping you can help me with this. I have a date outputted by a python program that I need to be able to access in another program.

The problem is that I have no idea how this date is formatted:

Format               Date
129893779638930000 - 2012-08-13 17:32:43

It is both date and time, and I'm really hoping somebody recognizes what format it is in, as I don't know python very well. Bonus points if you can show me how to convert it to a unix timestamp.

EDIT: The program that does this is a component for Foobar2000 (an extension for a music program). The component is shown here: http://www.foobar2000.org/components/view/foo_playcount, and it is the XML export feature that generates the odd date/timestamp.


Solution

  • 129893678626216000 looks like the unix timestamp in 1e-8 seconds (tens of nanoseconds): 1,298,936,786.262,160,00. It would represent:

    >>> from datetime import datetime
    >>> datetime.utcfromtimestamp(129893678626216000/1e8)
    datetime.datetime(2011, 2, 28, 23, 46, 26, 262160)
    

    EDIT: However your information "A file time is a 64-bit value that represents the number of 100-nanosecond intervals that have elapsed since 12:00 A.M. January 1, 1601 Coordinated Universal Time (UTC)" tells me to use:

    >>> from datetime import datetime, timedelta
    >>> datetime(1601, 1, 1, 0, 0, 0) + timedelta(seconds = 129893678626216000/1e7)
    datetime.datetime(2012, 8, 13, 21, 44, 22, 621599)
    

    where you get exactly what you awaited.

    You can also convert it directly to unix timestamp (number of seconds since 1970-01-01 00:00:00 UTC):

    >>> 129893678626216000 / 1e7 - 11644473600
    1344894262.6215992