I'm trying to use the date command to generate a file timestamp that the date command itself can interpret. However, the date command does not seem to like its own output, and I am not sure how to work around this. Case in point:
sh-4.2$ date
Fri Jan 3 14:22:19 PST 2014
sh-4.2$ date +%Y%m%dT%H%M
20140103T1422
sh-4.2$ date -d "20140103T1422"
Thu Jan 2 23:22:00 PST 2014
date appears to be interpreting the string with an offset of 15 hours. Are there any known workarounds for this?
Edit: this is not an issue of display:
sh-4.2$ date +%s
1388791096
sh-4.2$ date +%Y%m%dT%H%M
20140103T1518
sh-4.2$ date -d 20140103T1518 +%s
1388737080
sh-4.2$ python
Python 3.3.3 (default, Nov 26 2013, 13:33:18)
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 1388737080 - 1388791096
-54016
>>> 54016/3600
15.004444444444445
>>>
It's still off by 15 hours when displayed as a unix timestamp.
EDIT #1
Maybe I should pose this question a little differently. Say I have a list of ISO8601 basic timestamps of the form:
- YYYYMMDDThhmm
- YYYYMMDDThhmmss
What is the simplest way to convert them to the corresponding Unix timestamps?
For example:
- 20140103T1422 = 1388787720
- 20140103T142233 = 1388787753
20140103T1518
is not valid ISO 8601, it misses the timezone part