[comp.emacs] unix time -> human time

jr@bbn.com (John Robinson) (10/24/88)

In article <8810230418.AA20851@Portia.stanford.edu>, mahajan@PORTIA (Sanjoy Mahajan) writes:
>Does anyone have a lisp function to convert unix time (seconds since
>0:00 GMT Jan 1,1970) to the human-readable form printed by ls?  Thanks
>in advance.

Built-in: (current-time-string)
"Mon Oct 24 10:22:26 1988"

Also of note, (gnews-time)
((88 10 24) 10 23 28)

which follows:

 (defun gnews-time ()
   "Return current time in ((YY MM DD).(HH MM SS)) format."
   ;; This assumes (current-time-string) returns
   ;; something like: "Sun Jan 10 00:00:00 1988"
   (let* ((months '(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec))
	  (time (current-time-string))
	  (mm (read-from-string time 4))
	  (dd (read-from-string time (cdr mm)))
	  (d (car dd))
	  (di (cdr dd))
	  (h (read (substring time (+ 0 di) (+ 2 di))))
	  (m (read (substring time (+ 3 di) (+ 5 di))))
	  (s (read (substring time (+ 6 di) (+ 8 di))))
	  (y (read (substring time (+ 11 di) (+ 13 di))))
	  (mo (- 13 (length (memq (car mm) months)))))
     (cons (list y mo d) (list h m s))))

The latter due to Matthew Weemba, whose mailreader (gnews) I am using
at this moment and happily.
/jr
jr@bbn.com or bbn!jr