Time zones! So much fun. Looks like you're dealing with UTC offsets yourself, which gets messy as soon as you start thinking about DST. The good news is that there's a timezone database on most systems, which you should almost definitely use.<div>
<br><div>Take a look at python-dateutil (pip install python-dateutil):</div><div><br></div><div><div>>>> from datetime import datetime</div><div>>>> from dateutil import tz</div><div>>>> datetime.now()</div>
<div>datetime.datetime(2012, 9, 17, 6, 33, 57, 158555)</div><div><br></div><div>This is a so-called "naive datetime", it doesn't know about timezones. On my system, it returns a time in my local time zone. (It could have been GMT or something else entirely.) You have to call .replace() on a "naive datetime" to set the tzinfo member to make it a timezone-aware datetime object:</div>
<div><br></div><div>>>> AMS = tz.gettz('Europe/Amsterdam')</div><div>>>> ATH = tz.gettz('Europe/Athens')</div><div>>>> datetime.now().replace(tzinfo=AMS).astimezone(ATH)</div><div>
datetime.datetime(2012, 9, 17, 7, 37, 38, 573223, tzinfo=tzfile('/usr/share/zoneinfo/Europe/Athens'))</div><div><br></div><div>Voila, it seems like you're one hour ahead of me. :-)</div><div><br></div><div>HTH,</div>
<div><br></div><div>Joost</div><div><br><div class="gmail_quote">On 17 September 2012 06:25, Nick the Gr33k <span dir="ltr"><<a href="mailto:nikos.gr33k@gmail.com" target="_blank">nikos.gr33k@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello is there a better way of writing this:<br>
<br>
date = ( datetime.datetime.utcnow() + datetime.timedelta(hours=3) ).strftime( '%y-%m-%d %H:%M:%S')<br>
<br>
something like:<br>
<br>
date = datetime.datetime.utcnow(<u></u>hours=3).strftime( '%y-%m-%d %H:%M:%S')<br>
<br>
i prefer it if it could be written as this.<br>
<br>
Also what about dayligh savings time?<span class="HOEnZb"><font color="#888888"><br>
-- <br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/<u></u>mailman/listinfo/python-list</a><br>
</font></span></blockquote></div><br></div></div></div>