views:

82

answers:

2

In Python, what is the best way to get the RFC 3339 YYYY-MM-DD text from the output of gtk.Calendar::get_date()?

A: 

Hey Josh,

This might be useful to you:

http://www.tutorialspoint.com/python/time_strftime.htm

I've also just looked around for this gtk get_date method and I was able to find some code that handles it like this:

//here replace "self.window.get_date()" with "gtk.Calendar::get_date()"
year, month, day = self.window.get_date()
mytime = time.mktime((year, month+1, day, 0, 0, 0, 0, 0, 0))
return time.strftime("%x", time.gmtime(mytime))

So just replace "%x" with "%G-%m-%d" and I think it would work. Or at least it's worth a try.

treeface
+2  A: 

According to the docs, the get_date returns a tuple of (year,month,day), where month 0 to 11 and day is 1 to 31, so:

import datetime
dtTuple = calControl.get_date()
dtObj = datetime.datetime(dtTuple[0], dtTuple[1] + 1, dtTuple[2]) #add one to month to make it 1 to 12
print dtObj.strftime("%Y-%m-%d")
Mark