help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: problem with time-stamps on GNU/Linux and Windows


From: Giorgos Keramidas
Subject: Re: problem with time-stamps on GNU/Linux and Windows
Date: Fri, 05 Sep 2008 03:38:12 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (berkeley-unix)

On Thu, 04 Sep 2008 20:37:26 +0200, Seweryn Kokot <s.kokot@po.opole.pl> wrote:
> Well, (current-time-string) function returns the same strings on both
> systems, but in English, for example: "Thu Sep 4 20:16:51 2008". BTW
> why this function gives abbreviations in English and not the locale's
> ones?

Because this way the output is predictably formatted, and programs can
read it with a well-known, predefined format.  The `format-time-string'
function can be used for locale-aware results.

> Whereas this function
>
> (defun my-insert-time-stamp ()
>   (interactive)
>   (insert (format-time-string "%a %b %d %02H:%02M:%02S %Y")))
>
> on Windows gives
> (my-insert-time-stamp)
> Cz wrz 04 20:13:20 2008
>
> and on GNU/Linux:
> czw wrz 04 20:16:29 2008
>
> I raise this problem because org-mode has some problems parsing these
> inconsistent abbreviations.
>
> Is it possible to get the result of (my-insert-time-stamp) in English
> like in the case of the (current-time-string) function?

One way to get predictable timestamps in `my-insert-time-stamp' is to
temporarily alter the value of `system-time-locale':

    (defun my-insert-time-stamp ()
      (interactive)
      (insert (let ((system-time-locale "C"))
                (format-time-string "%a %b %d %02H:%02M:%02S %Y"))))

This will always use the "C" locale when displaying time, and the output
inserted by `my-insert-time-stamp' will be similar to:

    "Fri Sep 05 03:34:47 2008"

To make the timestamps inserted independent of the local timezone, it
may also be worth to call `format-time-string' with a third argument of
`T' to output the timestamp in UTC:

    (defun my-insert-time-stamp ()
      (interactive)
      (insert (let ((system-time-locale "C"))
                (format-time-string "%a %b %d %02H:%02M:%02S %Y" (current-time) 
t))))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]