Convert string to date

//1. Simple convertation var dateVar = "2010-10-30"; var d=new Date(dateVar); //2. Delimiter implementation var dateVar = "2010-10-30"; var dsplit = dateVar.split("-"); var d=new Date(dsplit[0],dsplit[1]-1,dsplit[2]); //3. With output var StringDate = "2013-4-13" var date = StringDate.split("-"); console.log(date[0]); console.log(date[1]); console.log(date[2]); NewDate = new Date(date[0],date[1]-1,date[2]);//Date object console.log(NewDate);

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.