Re: date/time
From: David M. Cooke (cookedm+news_at_physics.mcmaster.ca)
Date: 01/06/05
- Next message: Stephen Thorne: "Re: Decorators and static typing."
- Previous message: Kartic: "Re: Another PythonWin Excel question"
- In reply to: Thomas Guettler: "Re: date/time"
- Next in thread: Lee Harr: "Re: date/time"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 05 Jan 2005 18:33:31 -0500
Thomas Guettler <guettli@thomas-guettler.de> writes:
> Am Wed, 05 Jan 2005 15:08:37 +0100 schrieb Nader Emami:
>
>> L.S.,
>>
>> Could somebody help me how I can get the next format of date
>> from the time module?
>
> I don't understand your question. Do you want to have the next day?
>
> 20041231 --> 20050101 ?
>
> You can do it like this:
> - parse the string with time.strptime
> - timetuple[2]+=1
> - mktime(timetuple) # --> secs
> - strftime(localtime(secs))
Or using the datetime module:
import time, datetime
tt = time.strptime('20041231', '%Y%m%d')
t = datetime.date.fromtimestamp(time.mktime(tt))
# now in a easier-to-handle form than the time tuple
t += datetime.timedelta(days=1)
print t.strftime('%Y%m%d')
-- |>|\/|< /--------------------------------------------------------------------------\ |David M. Cooke |cookedm(at)physics(dot)mcmaster(dot)ca
- Next message: Stephen Thorne: "Re: Decorators and static typing."
- Previous message: Kartic: "Re: Another PythonWin Excel question"
- In reply to: Thomas Guettler: "Re: date/time"
- Next in thread: Lee Harr: "Re: date/time"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|