Last active
March 28, 2016 14:07
-
-
Save ozuma/7961472 to your computer and use it in GitHub Desktop.
FreeBSDとLinuxでの、dateコマンドの日付を指定したepoch扱い
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 共通 | |
"+%s"でepoch秒を出力する | |
# Linuxでは-dで日付を指定して+%sでepoch秒を出力 | |
$ date -d '2006/01/01 00:00:00' '+%s' | |
# FreeBSDでは、日付設定しない-jオプションと、日付フォーマット指定の-fオプションを使う | |
$ date -j -f "%Y%m%d%H%M.%S" "200601010000.00" "+%s" | |
# なおFreeBSDではフォーマットを省略するとYYYYMMDDHHMM.ssとみなすので、-fは省略可能 | |
$ date -j "200601010000.00" "+%s" | |
# ちなみにMacでも同様 | |
$ date -j -f "%Y%m%d%H%M.%S" "200601010000.00" "+%s" | |
# なおMacではフォーマットを省略すると[[[mm]dd]HH]MM[[cc]yy][.ss]とみなすのでFreeBSDとは違う | |
# つまりBSD系では-fでフォーマット指定は必ずした方がよさげ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment