user1597438
user1597438

Reputation: 2221

Formatting JSON date

I am converting json date from something like:

/Date(1224043200000)/

to

Mon Oct 22 16:37:04 UTC+0800 2012

using

var date = new Date(parseInt(dateData.substr(6), 10));

Is there any way to change the format to just show the month, date and year (Oct 22, 2012) instead of including the timezone and current day using similar if not the same code as the one I'm already using? Thanks so much.

Upvotes: 0

Views: 216

Answers (3)

user18428
user18428

Reputation: 1201

You may want to use momentjs With something like this :

moment(1224043200000).format("MMM Do, YYYY");

Upvotes: 0

Alex Ciminian
Alex Ciminian

Reputation: 11508

You can try this:

var formattedDate = date.toString().split(" ").slice(1, 4).join(" ");

Upvotes: 0

Tim Büthe
Tim Büthe

Reputation: 63734

Checkout datejs which has powerful formatting capabilities. Using the toString FormatSpecifiers, you can provide a custom pattern like this:

new Date().toString("MMM dd yyyy");

Upvotes: 1

Related Questions