... to a date object in another timezone
The JavaScript Date
object cannot represent another time zone. It is simply a timestamp, measured in milliseconds since 1970-01-01 midnight UTC, which you can see with .valueOf()
or .getTime()
.
When you call .toString()
on a Date
object, or otherwise coerce it into a string (such as when displaying it in the debug console), it converts the timestamp to the local time zone where the environment is running.
Therefore, despite any conversions you do with moment-timezone, you are still talking about the same moment in time, and thus will have the same timestamp in the resulting Date
object.
In other words, these are all equivalent:
moment("2016-08-04T23:30:37Z").toDate()
moment.utc("2016-08-04T23:30:37Z").toDate()
moment("2016-08-04T23:30:37Z").tz("Asia/Hong_Kong").toDate()
new Date("2016-08-04T23:30:37Z")
... because they all have the same internal timestamp of 1470353437000
moment("2016-08-04T23:30:37Z").valueOf() // 1470353437000
moment.utc("2016-08-04T23:30:37Z").valueOf() // 1470353437000
moment("2016-08-04T23:30:37Z").tz("Asia/Hong_Kong").valueOf() // 1470353437000
new Date("2016-08-04T23:30:37Z").valueOf() // 1470353437000
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…