user14657384
user14657384

Reputation:

Convert string into this format date - Day Name, month/dayNumber, hour pm or am

I have this string:

2020-11-20T14:00:00

How can i convert into

Friday, 11/20, 2:00 PM

Upvotes: 1

Views: 31

Answers (2)

s.kuznetsov
s.kuznetsov

Reputation: 15223

This is the date format you wanted.

var param = { weekday: 'long', month: 'numeric', day: 'numeric', hour: 'numeric', minute: 'numeric', hour12: true };
var date_today = new Date();

console.log(date_today.toLocaleDateString("en-US", param));

Upvotes: 2

Harshana
Harshana

Reputation: 5496

You can use moment.js to format the date time. Please check the example below:

var currentDate = "2020-11-20T14:00:00"
var formattedDate = moment(currentDate, "YYYY-MM-DDThh:mm:ss").format("dddd, MM/DD, hh:mm A")
console.log(formattedDate);
<script src="https://momentjs.com/downloads/moment.js"></script>

Upvotes: 2

Related Questions