[英]Convert into separate date and time into one string with format moment js
I am using moment js and new in this. 我在此使用moment js和new。 So right now I am getting separated time and date from html to javascript controller so I want to convert into one string with format in moment js.
所以现在我将时间和日期从html分离到javascript控制器,所以我想将其转换为一个具有js瞬间格式的字符串。
console.log($scope.timeTo);
console.log($scope.dateTO);
Console OutPut: 控制台输出:
04:00
23/05/2017
But I want to set time and date together with momentjs. 但是我想设置时间和日期以及moment.js。 Desired format:
所需格式:
2017-05-23T04:00:00
You can simply concat your strings and then parse it with moment. 您可以简单地连接字符串,然后根据需要对其进行解析 。
Then you can use format()
to get moment object in the format you need. 然后,您可以使用
format()
获取所需格式的矩对象。
var timeTo = '04:00'; var dateTo = '23/05/2017'; var m = moment(dateTo + timeTo, 'DD/MM/YYYY HH:mm'); console.log(m.format('YYYY-MM-DD[T]HH:mm:ss'));
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.