使用moment.js将日期转换为UTC [英] Convert date to UTC using moment.js
本文介绍了使用moment.js将日期转换为UTC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能很容易回答这个问题,但我似乎找不到让moment.js以毫秒为单位返回UTC日期时间的方法。以下是我正在做的事情:
Probably and easy answer to this but I can't seem to find a way to get moment.js to return a UTC date time in milliseconds. Here is what I am doing:
var date = $("#txt-date").val(),
expires = moment.utc(date);
知道我做错了吗?
推荐答案
可在文档中找到 。有了类似于时刻的图书馆,我恳请您阅读完整的文档。它非常重要。
This is found in the documentation. With a library like moment, I urge you to read the entirety of the documentation. It's really important.
假设输入文本是根据用户的当地时间输入的:
Assuming the input text is entered in terms of the users's local time:
var expires = moment(date).valueOf();
如果指示用户实际输入UTC日期/时间,则:
If the user is instructed actually enter a UTC date/time, then:
var expires = moment.utc(date).valueOf();
这篇关于使用moment.js将日期转换为UTC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文