Configure softwares
bash
alias date='date +%Y-%m-%d %H:%M:%S.%3N'
alias ls='ls --time-style=+%Y-%m-%d %H:%M:%S'
alias journalctl='journalctl -o short-iso-precise'
git
git config --global log.date format:'%Y-%m-%d %H:%M:%S'
Web browsing
Install this userscript:
yyyymmdd.user.js.
You need install a brower extension like Tampermonkey or Greasemonkey first.
Timestamp to yyyymmdd in programming languages
(Use unix timestamp 1300000000 as examples)
command line (local)
date -d@1300000000 '+%Y-%m-%d %H:%M:%S.%3N'
# 2011-03-13 07:06:40.000
python (local)
import datetime
dt = datetime.datetime.fromtimestamp(1300000000)
dt.strftime('%Y-%m-%d %H:%M:%S')
# 2011-03-13 15:06:40
JS (local)
var dt = new Date(1300000000 * 1000);
console.log(dt.toLocaleDateString('lt') + ' ' + dt.toLocaleTimeString('lt'));
// 2011-03-13 15:06:40
JS (GMT, ISO)
new Date(1300000000 * 1000).toISOString()
// 2011-03-13T07:06:40.000Z
C (local & GMT)
time_t ts = 1300000000;
struct tm stm;
localtime_r(&ts, &stm); // local
// gmttime_r(&ts, &stm); // GMT
char buf[sizeof("yyyy-mm-dd HH:MM:SS")];
strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", &stm);
// 2011-03-13 15:06:40
golang (local, with timezone)
// This is the most awful one. I bet you have to lookup this every time.
time.Unix(1300000000, 0).Format("2006-01-02 15:04:05.000-0700")
// 2011-03-13 15:06:40.000+0800