|
#1
| |||
| |||
| How to convert between date formats on the command line How would I convert a string, such as Code: 2012-01-31 18:54:55 +0000 Code: date -j -f "%a %b %d %T %Z %Y" "`date`" "+%s" |
|
#2
| ||||
| ||||
| Try this: Code: date --date='2012-01-31 18:54:55 +0000' +'%a %b %d %T %Z %Y' |
|
#3
| |||
| |||
| That command produces the output Code: usage: date [-jnu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
[-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format] |
|
#4
| ||||
| ||||
| Hmm... it looks like the shell utilities that are shipped with OS X aren't standard. Sorry I can't help more as I don't have my Mac with me. |
|
#5
| |||
| |||
| I'm looking for the time in seconds since Jan. 1, 1970. |
|
#6
| ||||
| ||||
| You'll have to combine the information from man 1 date and man 3 strftime Code: declare myDate="2012-01-31 18:54:55 +0000"
date -j -f "%Y-%m-%d %T %z" "${myDate}" "+%s"
__________________ Bjarne D Mathiesen København ; Danmark ; Europa Last edited by BjarneDM; February 3rd, 2012 at 05:08 PM. |
| The Following User Says Thank You to BjarneDM For This Useful Post: | ||
DominikHoffmann (February 3rd, 2012) | ||
![]() |
| Bookmarks |
| Tags |
| conversion, date, format, seconds, time |
| Thread Tools | |
| |