2014年1月17日

Emacs Lisp での時間の取り扱いについて調べた

decode-time を encode-time しても元に戻らない。。。

===
; -*- Mode: Emacs-Lisp ; Coding: utf-8 -*-

;;; Emacs-Lisp 形式での現在の時間
(current-time) ; => (21209 8840 966494 508000)

;;; 現在の日付を表示
(current-time-string (current-time)) ; => "Fri Jan 17 12:31:04 2014"

;;; Emacs-Lisp 形式から日付
;; (SECONDS MINUTES HOUR DAY MONTH YEAR DOW DST ZONE)
(decode-time (current-time)) ; => (4 31 12 17 1 2014 5 nil 0)

;;; 特定の日付けから Emacs-Lisp 形式に変換
;; (encode-time seconds minutes hour day month year)
(encode-time 4 31 12 17 1 2014 nil 0) ; => (21209 8840)

;;; Emacs-Lisp 形式から 浮動小数点数としてThe Epoch からの経過時間秒数
(time-to-seconds (current-time)) ; => 1389961864.968099

;;; 浮動小数点数としてThe Epoch 以来の経過時間秒数から Emacs-Lisp 形式に変換
(seconds-to-time (time-to-seconds (current-time))) ; => (21209 8840 968449 354172)

;;; 日付けの形式

;; the year
(format-time-string "%Y" (current-time)) ; => "2014"
;; within the century
(format-time-string "%y" (current-time)) ; => "14"
;; the century
(format-time-string "%C" (current-time)) ; => "20"

;; the year corresponding to the ISO week
(format-time-string "%G" (current-time)) ; => "2014"
;; within the century
(format-time-string "%g" (current-time)) ; => "14"

;; the numeric month
(format-time-string "%m" (current-time)) ; => "01"

;; the locale's abbreviated month name
(format-time-string "%b" (current-time)) ; => "Jan"
(format-time-string "%h" (current-time)) ; => "Jan"
;; the full name
(format-time-string "%B" (current-time)) ; => "January"

;; the day of the month, zero-padded
(format-time-string "%d" (current-time)) ; => "17"
;; blank-padded
(format-time-string "%e" (current-time)) ; => "17"

;; the numeric day of week from 1 (Monday) to 7
(format-time-string "%u" (current-time)) ; => "5"
;; from 0 (Sunday) to 6
(format-time-string "%w" (current-time)) ; => "5"

;; the locale's abbreviated name of the day of week
(format-time-string "%a" (current-time)) ; => "Fri"
;; the full name
(format-time-string "%A" (current-time)) ; => "Friday"

;; the week number starting on Sunday
(format-time-string "%U" (current-time)) ; => "02"
;; starting on Monday
(format-time-string "%W" (current-time)) ; => "02"
;; according to ISO 8601
(format-time-string "%V" (current-time)) ; => "03"

;; the day of the year
(format-time-string "%j" (current-time)) ; => "017"

;; the hour on a 24-hour clock
(format-time-string "%H" (current-time)) ; => "12"
;; on a 12-hour clock
(format-time-string "%I" (current-time)) ; => "12"
;; like %H only blank-padded
(format-time-string "%H" (current-time)) ; => "12"
;; like %I blank-padded
(format-time-string "%l" (current-time)) ; => "12"

;; the locale's equivalent of either AM or PM
(format-time-string "%p" (current-time)) ; => "PM"

;; the minute
(format-time-string "%M" (current-time)) ; => "31"

;; the second
(format-time-string "%S" (current-time)) ; => "04"

;; the nanosecond
(format-time-string "%N" (current-time)) ; => "981571072"
;; the microsecond
(format-time-string "%6N" (current-time)) ; => "981989"
;; the millisecond
(format-time-string "%3N" (current-time)) ; => "982"

;; the time zone name
(format-time-string "%Z" (current-time)) ; => "GMT"
;; the numeric form
(format-time-string "%z" (current-time)) ; => "+0000"

;; the number of seconds since 1970-01-01 00:00:00 +0000
(format-time-string "%s" (current-time)) ; => "1389961864"

;; the locale's date and time format
(format-time-string "%c" (current-time)) ; => "Fri Jan 17 12:31:04 2014"

;; the locale's "preferred" date format
(format-time-string "%x" (current-time)) ; => "01/17/14"

;; like "%m/%d/%y"
(format-time-string "%D" (current-time)) ; => "01/17/14"

;; like "%H:%M"
(format-time-string "%R" (current-time)) ; => "12:31"
;; like "%H:%M:%S"
(format-time-string "%T" (current-time)) ; => "12:31:04"
;; like "%I:%M:%S %p"
(format-time-string "%T" (current-time)) ; => "12:31:04"

;; the locale'sp "preferred" time format
(format-time-string "%X" (current-time)) ; => "12:31:04"

0 件のコメント:

コメントを投稿