Formatting A 12 Character DateTime Value
I have been working with an API recently that was giving me dates in a format that was twelve character string made up of just numbers. My initial thoughts were that it might be a Unix timestamp, but they were too long. I also knew what some of the sample dates needed to equate to, and when I would convert them from Unix timestamps, the results would be way off.
After much googling that I finally came across this answer on StackOverflow, which hinted that the date may be in milliseconds rather than seconds like most Unix timestamps.
For example, a timestamp of
790214400000 equates to January 16, 1995. In this format it would convert to November 25, 27010. But once converted from milliseconds to seconds, the timestamp becomes
790214400 which is the date that I needed.
If you need to play around with Unix timestamps, this online converter is quite handy: unixtimestamp.com.
Where would we be without StackOverflow?