datetime - Where can I find documentation on formatting a date in JavaScript? -


i noticed javascript's new date() function smart in accepting dates in several formats.

xmas95 = new date("25 dec, 1995 23:15:00") xmas95 = new date("2009 06 12,12:52:39") xmas95 = new date("20 09 2006,12:52:39") 

i not find documentation anywhere showing valid string formats while calling new date() function.

this converting string date. if @ opposite side, is, converting date object string, until under impression javascript doesn't have built-in api format date object string.

editor's note: following approach asker's attempt worked on particular browser not work in general; see answers on page see actual solutions.

today, played tostring() method on date object , surprisingly serves purpose of formatting date strings.

var d1 = new date(); d1.tostring('yyyy-mm-dd');       //returns "2009-06-29" in internet explorer, not firefox or chrome d1.tostring('dddd, mmmm ,yyyy')  //returns "monday, june 29,2009" in internet explorer, not firefox or chrome 

also here couldn't find documentation on ways can format date object string.

where documentation lists format specifiers supported date() object?

i love 10 ways format time , date using javascript , working dates.

basically, have 3 methods , have combine strings yourself:

getdate() // returns date getmonth() // returns month getfullyear() // returns year 

example:

<script type="text/javascript">     var d = new date();     var curr_date = d.getdate();     var curr_month = d.getmonth() + 1; //months 0 based     var curr_year = d.getfullyear();     console.log(curr_date + "-" + curr_month + "-" + curr_year); </script> 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -