javascript 使用 moment.js 从日期时间中提取时间
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29507504/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Extract time from datetime using moment.js
提问by Ramesh Rajendran
my datetime format is given below.
我的日期时间格式如下。
var datetime =Wed Apr 8 15:05:00 UTC+0530 2015;
I only want to get the time 15.05
我只想得到时间 15.05
回答by Swaraj Giri
回答by Ramesh Rajendran
You need to create moment object from your string. Then append .format()
您需要从字符串创建时刻对象。然后附加 .format()
var date = moment("Wed Apr 8 15:05:00 UTC+0530 2015").format('HH.mm');
alert(date);
var date = moment("Wed Apr 8 15:05:00 2015").format('HH.mm');
alert(date);
If you want to get "15.05", you will need to remove the "UTC+0530", because its modifying your time :) You can see examples here: http://momentjs.com/docs/#/displaying/format/
如果您想获得“15.05”,则需要删除“UTC+0530”,因为它会修改您的时间:) 您可以在此处查看示例:http: //momentjs.com/docs/#/displaying/format/