Current DateTime?
Posted by Russell Greenwood on Feb 10, 2007
Hey there -
Is there a way to use the current date/time as a variable to display as text?
Thanks.
Posted by Russell Greenwood on Feb 13, 2007
Hmm, date works fine, although I seem to get 000000 as the time.
Is there some other command I need to use if I want more than the date.
What I'm trying to achieve is a date-time stamp of just a run of number.
eg. 13022007102059 (day,month,year,hour,minute,second)
Posted by Tom De Smedt on Feb 13, 2007
OK, try this one:
from time import gmtime, strftime
timestamp = strftime("%d%m%Y%H%M%S", gmtime())
print timestamp
>>> 13022007190104
Posted by Russell on Feb 13, 2007
Works - but - it seems to be around 12 hours out... like, it's 9AM here and it spits out 2113 instead of 0913.
A timezone thing maybe?
Thanks for all your help - this is great.
Posted by Tom De Smedt on Feb 14, 2007
OK, now try using "localtime" instead of "gmtime":
from time import localtime, strftime
timestamp = strftime("%d%m%Y%H%M%S", localtime())
print timestamp
Posted by Tom De Smedt on Feb 11, 2007
Yes, you have to import the Python datetime library to do things with dates:
Notice how the strftime() command formats the output. All of the things you can do with strftime() are explained in the Python manual:
http://docs.python.org/lib/module-time.html