When creating a moment from a string, we first check if the string
matches known ISO 8601 formats, we then check if the string matches
the RFC 2822 Date time format before dropping to the fall back of new
Date(string) if a known format is not found.
Moment accepts the ISO 8601 and RFC 2822 formats for string parameters, and your input /Date(1538560800000+0200)/
is neither. Still, when you pass this to moment
, it tries to convert this to a string and ends up extracting the possible timestamp parameter, which is 1538560800000
. This can be seen in the following code, as both end up as the same values ..
let d = '/Date(1538560800000+0200)/'
moment(d).toString() // Wed Oct 03 2018 12:00:00 GMT+0200
moment(1538560800000).toString() // Wed Oct 03 2018 12:00:00 GMT+0200
1538560800000
when converted to GMT is Wed Oct 03 2018 10:00:00 GMT+0000, hence the output of the following code ..
moment.utc(d).toString() // Wed Oct 03 2018 10:00:00 GMT+0000
So, under no circumstance you're ever going to get the time as 14:00:00 as this timestamp does not represent that. And timestamps are always absolute (in GMT), there is no such thing as a local timestamp.
I feel the gap here is your wrong interpretation of the input string, you're thinking ..
- Convert
1538560800000
to local datetime, which is 3rd October, 12:00:00 (local)
- Add
+0200
hours to it, which means turn it to 3rd October, 14:00:00
But, the correct way to read it is ..
- Convert
1538560800000
to datetime, which is 3rd October, 10:00:00 (absolute/GMT)
+0200
represents the timezone of the source which is GMT+0200
.
Again, the first interpretation is wrong for the reason mentioned above - unix timestamps are always in GMT, they are never in local timezones.