[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to format this type of timestamp
From: |
Yuri Khan |
Subject: |
Re: How to format this type of timestamp |
Date: |
Mon, 5 Oct 2020 01:41:20 +0700 |
On Mon, 5 Oct 2020 at 00:00, Jean Louis <bugs@gnu.support> wrote:
> > If you don't care to be precise about timezones, that might
> > do the job ;-)
>
> It looks like time zone is not in that string, I am asking developers
> of Silence application about that.
Of course it’s not in there. By convention, Unix timestamps count
seconds (or milliseconds, in Java’s case) from the midnight between
1969-12-31 and 1970-01-01 as it happened in the UTC time zone. If a
program produces timestamps that look like Unix timestamps but count
from the midnight as it occurred in a different time zone, that’s a
bug in that program.
format-time-string will automatically adjust it to your local time
zone if you do not pass the optional third argument. If you do, its
value specifies the time zone to adjust to.
I think tomas’s remark was about the fact that you hardcode +03 in
your format string but you let Emacs auto-detect your local time zone.
This can cause an inconsistency if it detects a zone other than +03.
Two better options would be:
a. Let Emacs auto-detect the time zone and use the %Z format specifier
to preserve the detected time zone in the string.
(format-time-string "%F %T.%6N%Z" (/ 1599549641372 1000.0))
⇒ "2020-09-08 14:20:41.371999+07"
b. Pass an explicit time zone. In that case, it does not matter
whether you put that same time zone in the format string or use the %Z
specifier, but using %Z is more robust in the face of future
modifications to the code.
(format-time-string "%F %T.%6N%Z" (/ 1599549641372 1000.0)
(* 7 60 60))
⇒ "2020-09-08 14:20:41.371999+07"
(format-time-string "%F %T.%6N%Z" (/ 1599549641372 1000.0)
(* 3 60 60))
⇒ "2020-09-08 10:20:41.371999+03"
- How to format this type of timestamp, Jean Louis, 2020/10/03
- Re: How to format this type of timestamp, Eli Zaretskii, 2020/10/03
- Re: How to format this type of timestamp, Jean Louis, 2020/10/04
- Re: How to format this type of timestamp, Eli Zaretskii, 2020/10/04
- Re: How to format this type of timestamp, tomas, 2020/10/04
- Re: How to format this type of timestamp, Jean Louis, 2020/10/04
- Re: How to format this type of timestamp, tomas, 2020/10/04
- Re: How to format this type of timestamp, Jean Louis, 2020/10/04
- Re: How to format this type of timestamp,
Yuri Khan <=
- Re: How to format this type of timestamp, tomas, 2020/10/04
- Re: How to format this type of timestamp, Jean Louis, 2020/10/05
- Re: How to format this type of timestamp, tomas, 2020/10/05
- Re: How to format this type of timestamp, Tim Visher, 2020/10/05
- Re: How to format this type of timestamp, tomas, 2020/10/05