guile-user
[Top][All Lists]
Advanced

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

Re: Help formatting a UTC Timestamp


From: Chris Vine
Subject: Re: Help formatting a UTC Timestamp
Date: Tue, 14 Feb 2017 13:11:07 +0000

On Tue, 14 Feb 2017 12:27:16 +0000
Guy Baumann <address@hidden> 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



reply via email to

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