Because the value contains +0000
, you know that it has already been adjusted to a zero offset, which will make it equivalent to UTC. So the source time zone is not necessary.
Since you said you're using moment.js, then just pass the entire value in to the moment constructor, including the offset. It will automatically read that and adjust to local time zone.
moment("2014-03-17T11:44:39+0000")
If you don't want it adjusted, then just switch back to UTC.
moment("2014-03-17T11:44:39+0000").utc()
With either, you can use moment's fromNow
function to get the string output you're looking for. You don't need to call the utc
function if that's all you need:
moment("2014-03-17T11:44:39+0000").fromNow() // "2 hours ago" (or similar)
-
As an aside - the only difference between Z
and +0000
is a semantic one:
Z
is supposed to imply that the value is in UTC, whether originating in UTC or having been converted to UTC.+0000
or+00:00
is supposed to imply that the value was taken from a local time zone that is not offset from UTC at that point, for exampleEurope/London
in the winter, orAtlantic/Reykjavik
year-round.And if you follow RFC3339, then there's also the possibility of
-00:00
, which is supposed to imply that the local value is unknown but this value is understood to be UTC.
However, they're all referring to the same point, and I doubt Facebook is trying to imply anything other than you should treat the value as UTC, so I wouldn't worry about it. ;-)