datetime issue
Νικόλαος Κούρας
nikos.gr33k at gmail.com
Sun Sep 16 04:25:30 EDT 2012
Τη Κυριακή, 16 Σεπτεμβρίου 2012 8:53:57 π.μ. UTC+3, ο χρήστης Dennis Lee Bieber έγραψε:
> On Sat, 15 Sep 2012 22:15:38 -0700 (PDT), Íéêüëáïò Êïýñáò
>
> <nikos.gr33k at gmail.com> declaimed the following in
>
> gmane.comp.python.general:
>
>
>
>
>
> >
>
> > If i wanted to alter the following line, how would i write it?
>
> >
>
> > date = datetime.datetime.now()+datetime.timedelta(hours=2).strftime( '%y-%m-%d %H:%M:%S')
>
> >
>
> > But that doesnt work,
>
>
>
> What did you expect? Object methods bind tighter than operators so
>
> what you have is the equivalent of
>
>
>
> dn = datetime.datetime.now()
>
> dd = datetime.timedelta(hours=2).strftime(...)
>
> date = dn + dd
>
>
>
> Try
>
>
>
> >>> import datetime
>
> >>> date = datetime.datetime.now()+datetime.timedelta(hours=2).strftime( '%y-%m-%d %H:%M:%S')
>
> Traceback (most recent call last):
>
> File "<interactive input>", line 1, in <module>
>
> AttributeError: 'datetime.timedelta' object has no attribute 'strftime'
>
> >>> date = (datetime.datetime.now()+datetime.timedelta(hours=2) ).strftime( '%y-%m-%d %H:%M:%S')
>
> >>> date
>
> '12-09-16 03:50:44'
>
> >>>
>
>
>
> Note the ( ) wrapping the the + clause, with strftime() applied to
>
> the result of that...
>
> --
>
> Wulfraed Dennis Lee Bieber AF6VN
>
> wlfraed at ix.netcom.com HTTP://wlfraed.home.netcom.com/
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.
More information about the Python-list
mailing list