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


  • Twitter

    • Zo, alweer een uurtje bezig hier. Bijna alle open zaakjes van gisteren al afgewerkt. Zo verder met mijn puppet rewrite. 1 hr ago
    • @ariejan *Sits in a corner crying softly* in reply to ariejan 17 hrs ago
    • @ariejan Never had to install it, $customer has a 'specialist' party for that. I had to dive into the code to find the solution, though… :( in reply to ariejan 17 hrs ago
    • And it checks for permissions it doesn't need, but does strangeness if it doesn't get those permissions... 19 hrs ago
    • AAARRGGHHH Magento apparantly creates directories and files with 777 permissions... 19 hrs ago
    • More updates...

    Powered by Twitter Tools

  • Calender

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