24 Mar 2008, 15:41
Tags: , , , ,
Comments Off

Isoformat in Python 2.4

Sometimes I don’t like python. Just sometimes, I love it most of the times. But just look what hoops I need to jump through to get a current timestamp in ISO format:

from datetime import datetime, tzinfo, timedelta
import time

class TZ(tzinfo):
        def utcoffset(self,dt): return timedelta(seconds=time.timezone)
        def dst(self,dt): return timedelta(0)

a = datetime.now(TZ())
a= a.replace(microsecond = 0)
print a.isoformat()

That prints:

asterisk:~ tim$ python test.py
2008-03-24T13:38:06-01:00

Fugly…

Tags: , , , ,

 
  • Search


  • Calender

    March 2008
    M T W T F S S
    « Feb   Apr »
     12
    3456789
    10111213141516
    17181920212223
    24252627282930
    31  
  • Twitter

    Powered by Twitter Tools

  • RSS Delicious feed

  • Archives