1. NodeBox 1
    1. Homepage
    2. NodeBox 3Node-based app for generative design and data visualization
    3. NodeBox OpenGLHardware-accelerated cross-platform graphics library
    4. NodeBox 1Generate 2D visuals using Python code (Mac OS X only)
  2. Gallery
  3. Documentation
  4. Forum
  5. Blog

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 Tom De Smedt on Feb 11, 2007

Yes, you have to import the Python datetime library to do things with dates:

import datetime
print datetime.date.today()
>>> 2007-02-11
 
today = datetime.date.today().strftime("%Y, %B, %d")
print today
>>> 2007, February, 11


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



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