How do I get datetime to stop showing seconds?
Cameron Simpson
cs at cskk.id.au
Fri Oct 16 18:51:04 EDT 2020
On 16Oct2020 22:07, Albert-Jan Roskam <sjeik_appie at hotmail.com> wrote:
> I was using datetime.now().isoformat('T', 'seconds')
> Not 100% sure, but the strings seemed to be 2hrs off. Could it be that
> this Linux server was using the wrong time zone?
Maybe. This is why timezones are such a nightmare, and programmes
working with datetime as their primary structure are fragile (hmm, is
this _naive_ (untimezoned) datetime in local time? What _is_ local time? Was
the naive datetime obtained correctly? etc).
Hence the common recommendation to work in seconds since an epoch (on
UNIX that epoch is midnight 01 January 1970 GMT). Then timezones are
just when presenting to a human.
But also, on UNIX and UNIX-like (Linux) the timezone is an aspect of
your environment; setting the $TZ environment various suitably will
display times according to your preference. The system default for when
$TZ is not set is usually in the /etc/timezone file, but you can set $TZ
for yourself and have your own localtimes generally displayed.
Cheers,
Cameron Simpson <cs at cskk.id.au>
More information about the Python-list
mailing list