简体   繁体   中英

How to convert the String to expected date format in javascript?

I have the String 08082012, now i need to convert this into expected date format in js/jquery, for example the format is M/d/y. So result will be 08/08/2012.

Can you guys suggest me the possible ways to achieve? Thanks in advance.

If you know, that it only can have these 4 different formats use substring.

date = "08082012";

if(date.length == 8)
{
       new_date = date.substring(0,2) + "/" +  date.substring(2,4) + "/" +  date.substring(4);
}

if(date.length == 7)
...

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