Time-date as an integer

Jeff Lindholm jeff_news at lindholm.org
Tue Aug 24 14:17:26 EDT 2004


import datetime;
def calcNodeId(self):
    t = datetime.utcnow()
    val = ( (t.toordinal() * 24 * 60 * 60) + (t.hour * 60 * 60) + (t.minute 
* 60) + t.second ) * 1000000
    if val <= self._dTime:
        val = self._dTime + 1
    self._dTime = val
    return val

This should hadle your leap years. You will of course loose leap seconds, 
but I honestly not sure where you get those.....

"Charles Hixson" <charleshixsn at earthlink.net> wrote in message 
news:mailman.2271.1093328889.5135.python-list at python.org...
> This is a concept, not a finished program, and an extract from a class at 
> that...so forgive any illegalities, but:
> import    datetime;
>  def    calcNodeId(self):
>    t    =    datetime.utcnow()
>    val    =    t.year *    133920000000    +          #    12 months
>                    t.month    *    11160000000    +    #    31 days
>                    t.hour    *    3600000000    +         #    60 minutes
>                    t.minute    *    60000000    +         #    60 seconds
>                    t.second    *    1000000    +    t.microsecond
>    if    val <=    self._dTime:
>      val    =    self._dTime + 1
>    self._dTime    =    val
>    return    val
>
> This is the best that I've been able to come up with in getting a 
> date-time as an integer.  It feels like one of the time or date libraries 
> should have a better solution, but if so, I haven't found it.  Can anyone 
> suggest a better approach? 





More information about the Python-list mailing list