Ahsan Ali
Ahsan Ali

Reputation: 5135

Convert String Date to Time using Moment

I am using moment.js and I want to convert my string date into time.

I am getting the date in this format: Apr 01 and I want the output like 2017-01-01T00:00:00+05:00.

How can I achieve this?

Upvotes: 1

Views: 3637

Answers (1)

VincenzoC
VincenzoC

Reputation: 31482

Simply use moment(String, String) and format() method.

Here a working sample:

console.log(moment('Apr 01', 'MMM DD').format());
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script>

Upvotes: 5

Related Questions