简体   繁体   中英

Changing date format from 'yyyy-mm-dd' to 'yyyy MMM dd' or 'MMM dd, yyyy'

I have searched the site but haven't found an answer close to what I need. Basically my date is displayed correctly as " 2013-05-09 " but what I want is " 2013 March 19 " or to make it better " March 19, 2013 ".

Please provide me with links to where its been answered already if any.

you mean like this?

var monthStrings = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];

var yourDate = "2013-05-09";
var result = yourDate.split("-")[0] + " " + monthStrings[parseInt(yourDate.split("-")[1])] + " " + yourDate.split("-")[1];
alert(result);

I've looked for a predefined function in javascript that does this before, but when i searched, this was the simplest answer I got, and I use this too.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM