* Help formatting a UTC Timestamp
@ 2017-02-14 12:27 Guy Baumann
2017-02-14 12:48 ` tomas
2017-02-14 13:11 ` Chris Vine
0 siblings, 2 replies; 4+ messages in thread
From: Guy Baumann @ 2017-02-14 12:27 UTC (permalink / raw)
To: guile-user
I am trying to format a timestamp from an api. It is sent in the
format "2011-03-24T20:30:47Z"
what I want to output is something like this
(strftime "%d %b %g " (localtime (current-time)) )
However I am unable to work out how to do this, have tried using
string->date with results below
Enter `,help' for help.
scheme@(guile-user)> (define date "2011-03-24T20:30:47Z")
scheme@(guile-user)> (use-modules (srfi srfi-19))
scheme@(guile-user)> (string->date "~Y-m-dT~H:~M:SZ" date)
srfi/srfi-19.scm:1415:18: In procedure priv:string->date:
srfi/srfi-19.scm:1415:18: In procedure string->date: TIME-ERROR type bad-date-format-string: "2011-03-24T20:30:47Z"
Entering a new prompt. Type `,bt' for a backtrace or `,q' to continue.
scheme@(guile-user) [1]> (string->date date "~Y-m-dT~H:~M:SZ")
srfi/srfi-19.scm:1415:18: In procedure priv:string->date:
srfi/srfi-19.scm:1415:18: In procedure string->date: TIME-ERROR type bad-date-format-string: "~Y-m-dT~H:~M:SZ"
Entering a new prompt. Type `,bt' for a backtrace or `,q' to continue.
scheme@(guile-user) [2]> (string->date date "~Y-m-dT~H:~M:SZ")
srfi/srfi-19.scm:1415:18: In procedure priv:string->date:
srfi/srfi-19.scm:1415:18: In procedure string->date: TIME-ERROR type bad-date-format-string: "~Y-m-dT~H:~M:SZ"
Entering a new prompt. Type `,bt' for a backtrace or `,q' to continue.
scheme@(guile-user) [3]> (string->date "2000" "~Y")
srfi/srfi-19.scm:571:22: In procedure encode-julian-day-number:
srfi/srfi-19.scm:571:22: In procedure -: Wrong type: #f
thanks for any help
//guy
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Help formatting a UTC Timestamp
2017-02-14 12:27 Help formatting a UTC Timestamp Guy Baumann
@ 2017-02-14 12:48 ` tomas
2017-02-14 13:11 ` Chris Vine
1 sibling, 0 replies; 4+ messages in thread
From: tomas @ 2017-02-14 12:48 UTC (permalink / raw)
To: guile-user
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Tue, Feb 14, 2017 at 12:27:16PM +0000, Guy Baumann wrote:
> I am trying to format a timestamp from an api. It is sent in the
> format "2011-03-24T20:30:47Z"
>
> what I want to output is something like this
> (strftime "%d %b %g " (localtime (current-time)) )
>
> However I am unable to work out how to do this, have tried using
> string->date with results below
>
> Enter `,help' for help.
> scheme@(guile-user)> (define date "2011-03-24T20:30:47Z")
> scheme@(guile-user)> (use-modules (srfi srfi-19))
> scheme@(guile-user)> (string->date "~Y-m-dT~H:~M:SZ" date)
> srfi/srfi-19.scm:1415:18: In procedure priv:string->date:
> srfi/srfi-19.scm:1415:18: In procedure string->date: TIME-ERROR type bad-date-format-string: "2011-03-24T20:30:47Z"
You got the args reversed: it's first the date string, then the
template. Besides, you forgot a couple of tildes in your template
(e.g. it's "~m" and not just "m" and so on). Lastly, the template
for the zone offset is "~z" (a small z). The "big Z" in your input
string is just a concrete zone (afaik UTC).
This works:
scheme@(guile-user)> (define mydate "2011-03-24T20:30:47Z")
scheme@(guile-user)> (string->date mydate "~Y-~m-~dT~H:~M:~S~z")
$3 = #<date nanosecond: 0 second: 47 minute: 30 hour: 20 day: 24 month: 3 year: 2011 zone-offset: 0>
hth
- -- t
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)
iEYEARECAAYFAlii/LMACgkQBcgs9XrR2kbySACfY3yqQgFw4XWIBZo1Nif8exJ1
jwUAn04XBldYBIWDDhheEjI1nLbFbjhm
=MJ3B
-----END PGP SIGNATURE-----
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Help formatting a UTC Timestamp
2017-02-14 12:27 Help formatting a UTC Timestamp Guy Baumann
2017-02-14 12:48 ` tomas
@ 2017-02-14 13:11 ` Chris Vine
1 sibling, 0 replies; 4+ messages in thread
From: Chris Vine @ 2017-02-14 13:11 UTC (permalink / raw)
To: Guy Baumann; +Cc: guile-user
On Tue, 14 Feb 2017 12:27:16 +0000
Guy Baumann <guy@gammarus.co.uk> wrote:
> I am trying to format a timestamp from an api. It is sent in the
> format "2011-03-24T20:30:47Z"
>
> what I want to output is something like this
> (strftime "%d %b %g " (localtime (current-time)) )
>
> However I am unable to work out how to do this, have tried using
> string->date with results below
>
> Enter `,help' for help.
> scheme@(guile-user)> (define date "2011-03-24T20:30:47Z")
> scheme@(guile-user)> (use-modules (srfi srfi-19))
> scheme@(guile-user)> (string->date "~Y-m-dT~H:~M:SZ" date)
> srfi/srfi-19.scm:1415:18: In procedure priv:string->date:
> srfi/srfi-19.scm:1415:18: In procedure string->date: TIME-ERROR type
> bad-date-format-string: "2011-03-24T20:30:47Z"
>
> Entering a new prompt. Type `,bt' for a backtrace or `,q' to continue.
> scheme@(guile-user) [1]> (string->date date "~Y-m-dT~H:~M:SZ")
> srfi/srfi-19.scm:1415:18: In procedure priv:string->date:
> srfi/srfi-19.scm:1415:18: In procedure string->date: TIME-ERROR type
> bad-date-format-string: "~Y-m-dT~H:~M:SZ"
>
> Entering a new prompt. Type `,bt' for a backtrace or `,q' to continue.
> scheme@(guile-user) [2]> (string->date date "~Y-m-dT~H:~M:SZ")
> srfi/srfi-19.scm:1415:18: In procedure priv:string->date:
> srfi/srfi-19.scm:1415:18: In procedure string->date: TIME-ERROR type
> bad-date-format-string: "~Y-m-dT~H:~M:SZ"
>
> Entering a new prompt. Type `,bt' for a backtrace or `,q' to continue.
> scheme@(guile-user) [3]> (string->date "2000" "~Y")
> srfi/srfi-19.scm:571:22: In procedure encode-julian-day-number:
> srfi/srfi-19.scm:571:22: In procedure -: Wrong type: #f
You haven't got the escapes quite right. This will work:
(string->date date "~Y-~m-~dT~H:~M:~SZ")
As will this with skipping, given that your example uses numeric values:
(string->date date "~Y~m~dT~H~M~SZ")
Chris
^ permalink raw reply [flat|nested] 4+ messages in thread
* Help formatting a UTC TImestamp
@ 2017-02-14 7:45 Guy Baumann
0 siblings, 0 replies; 4+ messages in thread
From: Guy Baumann @ 2017-02-14 7:45 UTC (permalink / raw)
To: guile-user
I am trying to format a timestamp from an api. It is the format "2011-03-24T20:30:47Z"
what I want to produce is something like this
(strftime "%d %b %g " (localtime (current-time)) )
However I am unable to work out how to do this, have tried using string->date with results below
Enter `,help' for help.
scheme@(guile-user)> (define date "2011-03-24T20:30:47Z")
scheme@(guile-user)> (use-modules (srfi srfi-19))
scheme@(guile-user)> (string->date "~Y-m-dT~H:~M:SZ" date)
srfi/srfi-19.scm:1415:18: In procedure priv:string->date:
srfi/srfi-19.scm:1415:18: In procedure string->date: TIME-ERROR type bad-date-format-string: "2011-03-24T20:30:47Z"
Entering a new prompt. Type `,bt' for a backtrace or `,q' to continue.
scheme@(guile-user) [1]> (string->date date "~Y-m-dT~H:~M:SZ")
srfi/srfi-19.scm:1415:18: In procedure priv:string->date:
srfi/srfi-19.scm:1415:18: In procedure string->date: TIME-ERROR type bad-date-format-string: "~Y-m-dT~H:~M:SZ"
Entering a new prompt. Type `,bt' for a backtrace or `,q' to continue.
scheme@(guile-user) [2]> (string->date date "~Y-m-dT~H:~M:SZ")
srfi/srfi-19.scm:1415:18: In procedure priv:string->date:
srfi/srfi-19.scm:1415:18: In procedure string->date: TIME-ERROR type bad-date-format-string: "~Y-m-dT~H:~M:SZ"
Entering a new prompt. Type `,bt' for a backtrace or `,q' to continue.
scheme@(guile-user) [3]> (string->date "2000" "~Y")
srfi/srfi-19.scm:571:22: In procedure encode-julian-day-number:
srfi/srfi-19.scm:571:22: In procedure -: Wrong type: #f
thanks for any help
//guy
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-02-14 13:11 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-02-14 12:27 Help formatting a UTC Timestamp Guy Baumann
2017-02-14 12:48 ` tomas
2017-02-14 13:11 ` Chris Vine
-- strict thread matches above, loose matches on Subject: below --
2017-02-14 7:45 Help formatting a UTC TImestamp Guy Baumann
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).