datetime issue
pandora.koura at gmail.com
pandora.koura at gmail.com
Sun Sep 16 11:40:42 EDT 2012
Τη Κυριακή, 16 Σεπτεμβρίου 2012 6:30:15 μ.μ. UTC+3, ο χρήστης MRAB έγραψε:
> On 2012-09-16 09:25, Νικόλαος Κούρας wrote:
>
> [snip]
>
> >
>
> > date = ( datetime.datetime.now() + datetime.timedelta(hours=8) ).strftime( '%y-%m-%d %H:%M:%S')
>
> >
>
> > but iam giving +8 hours which is the time difference between texas, us where the server sits and Greece's time.
>
> >
>
> > cant we somehow tell it to use GMT+2 ?
>
> >
>
> > also it would be nice if datetime.datetime.now(GMT+2) can be used.
>
> >
>
> In programming, you need attention to details.
>
>
>
> My reply didn't use datetime.datetime.now(), it used
>
> datetime.datetime.utcnow().
>
>
>
> datetime.datetime.now() gives the local time (local to the system on
>
> which it is running).
>
>
>
> datetime.datetime.utcnow() gives the UTC (GMT) time, which is the same
>
> everywhere.
>
>
>
> The line should be this:
>
>
>
> date = (datetime.datetime.utcnow() + datetime.timedelta(hours=8)
>
> ).strftime('%Y-%m-%d %H:%M:%S')
>
>
>
> I've also used '%Y' instead of '%y' because I prefer 4 digits for the year.
Cant it be written more easily as:
date = (datetime.datetime.utcnow(+2)
i know this is not thhe correct syntax but it just needs a way to add GMT+2 hours since utc=gmt
More information about the Python-list
mailing list