datetime question

Joel Goldstick joel.goldstick at gmail.com
Mon Nov 11 08:41:00 EST 2013


On Mon, Nov 11, 2013 at 4:57 AM, Νίκος Αλεξόπουλος
<nikos.gr33k at gmail.com> wrote:
> Στις 8/11/2013 11:11 μμ, ο/η Νίκος Αλεξόπουλος έγραψε:
>
>> Is there someway to write the following line even better with the
>> ability to detect daylight saving time by itself so i don't have to
>> alter the line manually when time changes?
>>
>> lastvisit = ( datetime.utcnow() + timedelta(hours=2) ).strftime(
>> '%y-%m-%d %H:%M:%S' )        # MySQL datetime format
>>
>> Thanks.
>
>
>
> Someone has an idea what to add to this line to automatically adjust itself

Three days ago Mark Lawrence pointed you to a stack overflow answer to
your question.  While it didn't suit your demand for a single line
answer, it could easily be made into a function which returned the
string format that you requested.  You've been around long enough to
try to work that out for yourself.  If you yourself had returned with
a one liner to perform what Mark showed you, I can imagine a lot of
people would be impressed at your dedication!

I think you are oversimplifying the problem.  I recall that you server
is in Germany, and you are in Greece.  If these are two different time
zones, I am guessing that the German time will be given.  Also, any
linux user who runs package updates regularly (thinking Ubuntu)
realizes that some file that starts with tz gets changed quite often.
This is because time zones are set by governments, and the date of
change from standard to daylight time can be differently, depending
upon the location and the governing body.

I pose this question to you:

Why not display UTC?  If it is so important to you to display local
time, why do you think that your host's local time is something that
is useful for a visitor?  Daylight savings time is more complicated
that you have suggested
> if DST happens?

If you insist upon displaying the local time of your server, you
should not be hardcoding in a 2 hour difference.  Let the python
library figure out the delta by giving the country code
> --
> https://mail.python.org/mailman/listinfo/python-list



-- 
Joel Goldstick
http://joelgoldstick.com



More information about the Python-list mailing list