I am using moment js and new in this. 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.
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. 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.
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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.