Τη Κυριακή, 16 Σεπτεμβρίου 2012 8:53:57 π.μ. UTC+3, ο χρήστης Dennis Lee Bieber έγραψε: > On Sat, 15 Sep 2012 22:15:38 -0700 (PDT), Íéêüëáïò Êïýñáò > > <nikos.gr...@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 > > wlfr...@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. -- http://mail.python.org/mailman/listinfo/python-list