[Tutor] incrementing one minute
pa yo
payo2000 at gmail.com
Mon Mar 30 17:05:01 CEST 2009
I fixed it by re-setting my system clock to GMT.
... it seems a bit of a botch but it works.
Payo
On Mon, Mar 30, 2009 at 4:52 PM, pa yo <payo2000 at gmail.com> wrote:
> I need to add one minute to a string that has a date and a time in
> YYYYMMDDHHMM format.
> e.g: 200903281346 should become 200903281347
>
> the following script converts the string into time and adds one
> minute; but somehow I also add an hour and I don't understand why.
>
> ====================
>
> import time
>
> #set the initial time as a string and convert it into time format:
> fromtimestring = '200903281346'
> fromtimetime = time.strptime(fromtimestring, "%Y%m%d%H%M")
> #convert this time format into UNIX time (seconds since the start of UNIX time):
> fromtimeseconds = time.mktime(fromtimetime)
> #add 60 seconds and reformat the result into the YYYYMMDDHHMM format
> totimeseconds = fromtimeseconds + 60
> totimetime = time.gmtime(totimeseconds)
> # convert the new time into a string:
> totimestring = time.strftime("%Y%m%d%H%M", totimetime)
>
> #print the results:
> print (fromtimestring)
> print (fromtimetime)
> print (totimetime)
> print (totimestring)
>
> ================
>
> any help or suggestions would be much appreciated.
>
>
> Payo
>
More information about the Tutor
mailing list