-2

How can convert a string to date format in java script. I want to convert this string "Wed May 15 2013 11:30:00 GMT 0530 (IST)" into a date format.

  • 1
    You mean like `var time = new Date(); return time.toString();` ? – Simon May 16 '13 at 10:23
  • check this question http://stackoverflow.com/questions/1056728/formatting-a-date-in-javascript – imkost May 16 '13 at 10:27
  • Check the post imkost linked and if you still have problems getting the right format, write in your question what format you need the datetime to be in. – Simon May 16 '13 at 10:30
  • Yes Simon you are right you got my point. I want to in the following format :- "YY-MM-dd" – Ravindra Shekhawat May 16 '13 at 10:36
  • possible duplicate of [How can I convert string to datetime with format specification in JavaScript?](http://stackoverflow.com/questions/476105/how-can-i-convert-string-to-datetime-with-format-specification-in-javascript) – Bergi May 16 '13 at 11:45

2 Answers2

0

Use Date.parse function

// create Date object from string
var d = new Date(Date.parse("Wed May 15 2013 11:30:00 GMT 0530 (IST)"));
var dateString = d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate();
Jan Turoň
  • 31,451
  • 23
  • 125
  • 169
-1
<script type="javascript">
   var dateTime = new Date(); 
   alert(dateTime.toString());
</script>

Here is the working Demo: Demo

Vaibhav Jain
  • 3,729
  • 3
  • 25
  • 42