![]() |
I can print 'today', but can I print 'yesterday'?
:
import timeAside: Rather than bumping the other thread again: I got a working MediaWiki bot after finding I was using the wrong version of python with the pywikipediabot. |
I looked into it. I thought there might be a way to set the timezone back 24 hours. Doesn't look like there is.
Maybe you could change your computer clock with the win32api? But that might be very inconvenient. I'd just make a short dictionary of how many days in each month, then a general function around that. Wouldn't be too hard (depending how experienced you are). |
Wee. I decided to try it out myself.
time.gmtime() will convert the seconds since epoch to a date. So if we take the current seconds since epoch time.time() and offset it back a day, voila! :
import timeI'm -5 from GMT, so if I then set it to -29, it gives me yesterday's date. Hope this helps. =D |
The module datetime is the one you want to use:
:
import datetime |
Thanks both, but it's not in the form I'd like, ie '31 January 2006', '1 Febraury 2006'. Is that as simple? I checked some of the documentation on ptyhon.org, but didn't immediately find anything.
|
You could do that easily by yourself...
o_O I'll throw something up, just a moment. EDIT: :
import timeThen just change -5 to how many hours you are from GMT. |
Quote:
:
import datetime |
Quote:
-T. |
With Windows use the same code you use for time:
:
import datetime |
Quote:
|
| All times are GMT -5. The time now is 4:31 PM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC