moment.duration().toJSON();
当将时长对象序列化为 JSON 时,它将会表示为 ISO8601 字符串。
JSON.stringify({
postDuration : moment.duration(5, 'm')
}); // '{"postDuration":"PT5M"}'
无效的时长返回 json 表示的 Invalid Date
。
moment.duration().toJSON();
When serializing a duration object to JSON, it will be represented as an ISO8601 string.
JSON.stringify({
postDuration : moment.duration(5, 'm')
}); // '{"postDuration":"PT5M"}'
Invalid durations return Invalid Date
as json representation.