admin管理员组文章数量:1384207
I am using moment-timezone and this is the code:
$('#myDiv').text(moment.tz('America/Los_Angeles').format('DD-MM-YYYY HH:mm:ss'));
This will output something like this:
06-10-2017 08:44:15
What I want to do is to put the date and time in 2 different elements but at this point it's all together in the same output.
How can I do this with moment?
I am using moment-timezone and this is the code:
$('#myDiv').text(moment.tz('America/Los_Angeles').format('DD-MM-YYYY HH:mm:ss'));
This will output something like this:
06-10-2017 08:44:15
What I want to do is to put the date and time in 2 different elements but at this point it's all together in the same output.
How can I do this with moment?
Share Improve this question asked Oct 6, 2017 at 15:46 user8398743user8398743 1- You can simply concat your strings and then parse it with moment. – Cupkek05 Commented Oct 6, 2017 at 15:52
2 Answers
Reset to default 3your can use
var datetime = moment.tz('America/Los_Angeles').format('DD-MM-YYYY HH:mm:ss').split(' ');
and the value of datetime is ['06-10-2017', '08:44:15']
You could do it like this:
$('#myDateDiv').text(moment.tz('America/Los_Angeles').format('DD-MM-YYYY'));
$('#myTimeDiv').text(moment.tz('America/Los_Angeles').format('HH:mm:ss'));
Or if you wanted to call moment
only once you could split up the result by the space between the date and time:
var datetime = moment.tz('America/Los_Angeles').format('DD-MM-YYYY HH:MM:SS').split(' ');
$('#myDateDiv').text(datetime[0]);
$('#myTimeDiv').text(datetime[1]);
本文标签: momentjsjavascript moment separate date and timeStack Overflow
版权声明:本文标题:momentjs - javascript moment separate date and time - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744471612a2607832.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论