Python: Getting the Current Year, Day, Month, Hour, Minute, Second… Even Microsecond? EH?

This is more to be filed under “I don’t want to have to search the wabz for this again so I’m using my blog to post something so I don’t have to”, but if someone else in this world gets something from this, then well someone else in the world gets something from this. As I’m the only person I care about, helping myself is about as far as my concern goes.

This is really simple:

import datetime from datetime

    def someMethod():

       currentSecond= datetime.now().second
       currentMinute = datetime.now().minute
       currentHour = datetime.now().hour

       currentDay = datetime.now().day
       currentMonth = datetime.now().month
       currentYear = datetime.now().year

And actually there is one more if you print out datetime.now():

2010-09-24 10:06:06.599000

That .599000 is called microsecond:

       datetime.now().microsecond

Anyhow, thanks for playing.