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

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

Re: parsing a date


From: Eric Abrahamsen
Subject: Re: parsing a date
Date: Sun, 23 Dec 2012 13:55:12 +0800
User-agent: Gnus/5.130006 (Ma Gnus v0.6) Emacs/24.2 (gnu/linux)

"WJ" <w_a_x_man@yahoo.com> writes:

> Eric Abrahamsen wrote:
>
>> I'm reading in files with dates in this format: "2011-11-25". I need to
>> write them out as "2011/11/25". Instead of just manhandling the strings
>> (I'll likely need this date information in other places) I wanted to
>> parse the strings into proper date objects, then format them back into
>> strings. `date-to-time' doesn't work because (parse-time-string
>> "2011-11-15") gives me:
>> 
>> (nil nil nil 15 11 2011 nil nil nil)
>> 
>> Which is not acceptable to `encode-time', because it requires integers,
>> not nil. I can't believe this is quite this complicated: do I really
>> have to replace all the nils with 0 myself?
>> 
>> Any pointers gratefully accepted,
>> 
>> Eric
>
> (format-time-string "%Y/%m/%d"
>   (apply 'encode-time 0 0 0
>     (nthcdr 3 (parse-time-string "2011-11-15"))))
>
> ==> "2011/11/15"

Only just saw this -- thanks very much!




reply via email to

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