Skip to content

Instantly share code, notes, and snippets.

@asserchiu
Last active January 1, 2016 08:49
Show Gist options
  • Save asserchiu/8121275 to your computer and use it in GitHub Desktop.
Save asserchiu/8121275 to your computer and use it in GitHub Desktop.
UNIX date time format conversion using `sed`.
$ cat dm.test
25/12/2013,20:00:00,asdf,qwer,zxcv
$ sed -n -e "s_\(..\)/\(..\)/\(....\),_\3-\2-\1T_p" dm.test
2013-12-25T20:00:00,asdf,qwer,zxcv
$ date --universal --rfc-3339 ns|sed -ne "s_^\(....-..-..\)\ \(..:..:..\....\).*_\1T\2Z_p"
2013-11-15T19:39:42.146Z
$ alias date.toISOString='date --universal --rfc-3339 ns|sed -ne "s_^\(....-..-..\)\ \(..:..:..\....\).*_\1T\2Z_p"'
$ date.toISOString
2013-12-03T11:07:09.591Z
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment