F
Ferrous Cranus
Στις 12/11/2013 4:03 μμ, ο/η Joel Goldstick ÎγÏαψε:
Joel i must thank you for your help.
I cannot believe it was so simple.
lastvisit = ( datetime.now() ).strftime('%y-%m-%d %H:%M:%S') # MySQL
datetime format
Tnhe server is self aware of its location so why use utcnow() +
timedelte( some_digit_here ) when you can just use just now()
Great solution, no need for function declaration and importing of new
pytz modules.
Simple and straightforward, Thank you!
I think that is a great solution. What would happen if you just did this:
lastvisit2 = (datetime.now()).strftime('%y-%m-%d %H:%M:%S' )
Why don't you try it out and see what you find?
(PS, this was pointed out to me by a pro, so I did a little reading in
the python docs and took Andy's excellent code and added a couple of
lines to test.)
I switched to my local timezone "US/Eastern" to test. My machine is
running Ubuntu. It seems to know that it is in the Eastern US. If
your server knows where it lives, then this should work for you also.
If it is set to a different timezone, I'm not sure I could help you,
but I'm sure someone could. You even might ask your host if this is
possible.
----------------------
#! /usr/bin/env python
from datetime import datetime, time, timedelta
import time
import pytz
def is_dst(zonename):
tz = pytz.timezone(zonename)
now = pytz.utc.localize(datetime.utcnow())
return now.astimezone(tz).dst() != timedelta(0)
def dst_greece():
#if is_dst("Europe/Kiev") :
if is_dst("US/Eastern") :
diff = -6
else:
diff = -5
return diff
lastvisit = (datetime.utcnow()
+timedelta(hours=dst_greece())).strftime('%y-%m-%d %H:%M:%S' )
lastvisit2 = (datetime.now()).strftime('%y-%m-%d %H:%M:%S' )
print lastvisit
print lastvisit2
Joel i must thank you for your help.
I cannot believe it was so simple.
lastvisit = ( datetime.now() ).strftime('%y-%m-%d %H:%M:%S') # MySQL
datetime format
Tnhe server is self aware of its location so why use utcnow() +
timedelte( some_digit_here ) when you can just use just now()
Great solution, no need for function declaration and importing of new
pytz modules.
Simple and straightforward, Thank you!