unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Storing hours, minutes, seconds, and nanoseconds from format-time-string
@ 2022-12-06  9:23 Heime
  2022-12-06 10:19 ` Stephen Berman
  2022-12-06 15:22 ` Thibaut Verron
  0 siblings, 2 replies; 7+ messages in thread
From: Heime @ 2022-12-06  9:23 UTC (permalink / raw)
  To: Heime via Users list for the GNU Emacs text editor


I am getting the time using the format "%FT%T.%N%z".

(format-time-string "%FT%T.%N%z" nil tzone)

From the result I need to get the hours, minutes, seconds,
and nanoseconds to store them into four numeric variables.

How can I do this from the output of "format-time-string".



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Storing hours, minutes, seconds, and nanoseconds from format-time-string
  2022-12-06  9:23 Storing hours, minutes, seconds, and nanoseconds from format-time-string Heime
@ 2022-12-06 10:19 ` Stephen Berman
  2022-12-06 12:07   ` Heime
  2022-12-06 15:22 ` Thibaut Verron
  1 sibling, 1 reply; 7+ messages in thread
From: Stephen Berman @ 2022-12-06 10:19 UTC (permalink / raw)
  To: Heime; +Cc: Heime via Users list for the GNU Emacs text editor

On Tue, 06 Dec 2022 09:23:24 +0000 Heime <heimeborgia@protonmail.com> wrote:

> I am getting the time using the format "%FT%T.%N%z".
>
> (format-time-string "%FT%T.%N%z" nil tzone)
>
> From the result I need to get the hours, minutes, seconds,
> and nanoseconds to store them into four numeric variables.
>
> How can I do this from the output of "format-time-string".

You can pass the output to string-split, splitting on non-digits,
i.e. using "[^[:digit:]]" as the value of the SEPARATORS argument.

Steve Berman



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Storing hours, minutes, seconds, and nanoseconds from format-time-string
  2022-12-06 10:19 ` Stephen Berman
@ 2022-12-06 12:07   ` Heime
  2022-12-06 12:14     ` Stephen Berman
  2022-12-06 14:34     ` Emanuel Berg
  0 siblings, 2 replies; 7+ messages in thread
From: Heime @ 2022-12-06 12:07 UTC (permalink / raw)
  To: Stephen Berman; +Cc: Heime via Users list for the GNU Emacs text editor

Am getting (void-function string-split) on "string-split".




Sent with Proton Mail secure email.

------- Original Message -------
On Tuesday, December 6th, 2022 at 10:19 AM, Stephen Berman <stephen.berman@gmx.net> wrote:


> On Tue, 06 Dec 2022 09:23:24 +0000 Heime heimeborgia@protonmail.com wrote:
> 
> > I am getting the time using the format "%FT%T.%N%z".
> > 
> > (format-time-string "%FT%T.%N%z" nil tzone)
> > 
> > From the result I need to get the hours, minutes, seconds,
> > and nanoseconds to store them into four numeric variables.
> > 
> > How can I do this from the output of "format-time-string".
> 
> 
> You can pass the output to string-split, splitting on non-digits,
> i.e. using "[^[:digit:]]" as the value of the SEPARATORS argument.
> 
> Steve Berman



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Storing hours, minutes, seconds, and nanoseconds from format-time-string
  2022-12-06 12:07   ` Heime
@ 2022-12-06 12:14     ` Stephen Berman
  2022-12-06 14:34     ` Emanuel Berg
  1 sibling, 0 replies; 7+ messages in thread
From: Stephen Berman @ 2022-12-06 12:14 UTC (permalink / raw)
  To: Heime; +Cc: Heime via Users list for the GNU Emacs text editor

On Tue, 06 Dec 2022 12:07:05 +0000 Heime <heimeborgia@protonmail.com> wrote:

> Am getting (void-function string-split) on "string-split".

It's the same as `split-string'.  The alias was introduced in Emacs 29,
so I guess you're using an earlier version.

Steve Berma

> ------- Original Message -------
> On Tuesday, December 6th, 2022 at 10:19 AM, Stephen Berman
> <stephen.berman@gmx.net> wrote:
>
>
>> On Tue, 06 Dec 2022 09:23:24 +0000 Heime heimeborgia@protonmail.com wrote:
>>
>> > I am getting the time using the format "%FT%T.%N%z".
>> >
>> > (format-time-string "%FT%T.%N%z" nil tzone)
>> >
>> > From the result I need to get the hours, minutes, seconds,
>> > and nanoseconds to store them into four numeric variables.
>> >
>> > How can I do this from the output of "format-time-string".
>>
>>
>> You can pass the output to string-split, splitting on non-digits,
>> i.e. using "[^[:digit:]]" as the value of the SEPARATORS argument.
>>
>> Steve Berman



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Storing hours, minutes, seconds, and nanoseconds from format-time-string
  2022-12-06 12:07   ` Heime
  2022-12-06 12:14     ` Stephen Berman
@ 2022-12-06 14:34     ` Emanuel Berg
  2022-12-06 15:04       ` Thibaut Verron
  1 sibling, 1 reply; 7+ messages in thread
From: Emanuel Berg @ 2022-12-06 14:34 UTC (permalink / raw)
  To: help-gnu-emacs

Heime wrote:

> Am getting (void-function string-split) on "string-split".

Split the format string, i.e. use `format-time-string' several
times for each data you want to acquire ...

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Storing hours, minutes, seconds, and nanoseconds from format-time-string
  2022-12-06 14:34     ` Emanuel Berg
@ 2022-12-06 15:04       ` Thibaut Verron
  0 siblings, 0 replies; 7+ messages in thread
From: Thibaut Verron @ 2022-12-06 15:04 UTC (permalink / raw)
  To: help-gnu-emacs

On 06/12/2022 15:34, Emanuel Berg wrote:
> Heime wrote:
>
>> Am getting (void-function string-split) on "string-split".
> Split the format string, i.e. use `format-time-string' several
> times for each data you want to acquire ...
Since the time will change between each call, it is likely that you will 
end up with inconsistent values if you do that.



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Storing hours, minutes, seconds, and nanoseconds from format-time-string
  2022-12-06  9:23 Storing hours, minutes, seconds, and nanoseconds from format-time-string Heime
  2022-12-06 10:19 ` Stephen Berman
@ 2022-12-06 15:22 ` Thibaut Verron
  1 sibling, 0 replies; 7+ messages in thread
From: Thibaut Verron @ 2022-12-06 15:22 UTC (permalink / raw)
  To: Heime, Heime via Users list for the GNU Emacs text editor

On 06/12/2022 10:23, Heime wrote:

> I am getting the time using the format "%FT%T.%N%z".
>
> (format-time-string "%FT%T.%N%z" nil tzone)
>
>  From the result I need to get the hours, minutes, seconds,
> and nanoseconds to store them into four numeric variables.
>
> How can I do this from the output of "format-time-string".

Dear Heime,

As others have already pointed out, you might benefit by reading up on 
the etiquette rules applicable when asking strangers for help on the 
internet.

Things like saying please and thank you, showing minimal effort, 
expressing the problem clearly... would go a long way in improving the 
form of your communication, and in turn in getting better and faster 
answers.

This community is very friendly and most cannot say no to an elisp 
problem, but nobody has unlimited patience.

---

You can use format-time-string to directly get the data you want, and 
then separate it either by using string processing, or by making the 
output a valid elisp sexp.

For example:

(split-string (format-time-string "%H %M %S %N")) ;; using string processing

(car (read-from-string (format-time-string "(%H %M %S %N)"))) ;; using 
elisp processing


Good luck.

Thibaut






^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-12-06 15:22 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-06  9:23 Storing hours, minutes, seconds, and nanoseconds from format-time-string Heime
2022-12-06 10:19 ` Stephen Berman
2022-12-06 12:07   ` Heime
2022-12-06 12:14     ` Stephen Berman
2022-12-06 14:34     ` Emanuel Berg
2022-12-06 15:04       ` Thibaut Verron
2022-12-06 15:22 ` Thibaut Verron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).