时间格式转换
# date 到 timestamp:
date -d "2014-02-26 17:43" +%s
1393407780
# 将时间字符串转换为毫秒级时间截
D="2014-06-30 00:00:00";expr $(date -d "$D" +%s) \* 1000
D="2014-06-30 00:00:00";expr $(date -d "$D" +%s) '*' 1000
# timestamp 到 date
date -d '1970-1-1 UTC 1393404758 sec'
Wed Feb 26 16:52:38 CST 2014
# timestamp 到 UTC date
date -d '1970-1-1 UTC 1393404758 sec' -u
Wed Feb 26 08:52:38 UTC 2014
# 当前时间UTC timestamp
date +%s
1393407544
# 取当前时间的timestamp,再用date -d转换为str格式
date;date -d "1970-1-1 UTC $(date +%s) sec"
Wed Feb 26 17:42:16 CST 2014
Wed Feb 26 17:42:16 CST 2014
# mysql转换时间戳
mysql> select FROM_UNIXTIME(1404190686) FROM DUAL;
+---------------------------+
| FROM_UNIXTIME(1404190686) |
+---------------------------+
| 2014-07-01 12:58:06 |
+---------------------------+