4
1
I have a bash script that takes a date string containing the day-of-year (Julian day) and converts it to another format. The %j
format character isn't parsing the string as I'd expect per the docs (man date
and man strftime
). For example, when I do this:
date -j -f "%Y %j %H %M %S" "2013 2 12 34 56" "+%a %b %d %T %Z %Y"
I get:
Sat Mar 09 12:34:56 UTC 2013
Why is it showing today's day (Sat March 09
)? Shouldn't it instead show Wed Jan 02
(day 2 of 2013)?
It seems to work fine with other formats. For example, this:
date -j -f "%Y %m %d %H %M %S" "2013 01 02 12 34 56" "+%a %b %d %T %Z %Y"
correctly gives Wed Jan 02 12:34:56 UTC 2013
.
What's going on? Am I using the %j
character correctly? I get identical results on OS 10.10 Yosemite and 10.11 El Capitan.
2
I would have expected that to work also, but I find on my laptop running OS X El Capitan that if I use *date -j -f "%Y %j %H %M %S" "2017 n 12 34 56" "+%a %b %d %T %Z %Y"* where n is any number from 001 to 365, I always see "Thu Mar 09" returned, yet "man date" shows "parsing is done using strptime(3)." And per http://man7.org/linux/man-pages/man3/strptime.3.html, %j should be day of the year, but it is obviously not working.
– moonpoint – 2017-03-10T03:09:36.427@moonpoint : Thanks for confirming this bug. (And unfortunately it appears I don't yet have privileges to up-vote your comment.) As a relative newbie to SE, I'm not sure what my most helpful next step would be: wait for other comments/answers, edit my original question and refer to your comment, post an answer to my question, or just call it done. Time for me to go read the SE FAQ... – jt bullitt – 2017-03-10T03:31:22.697