Tuesday 15 March 2011

javascript - Converting date string from dashes to forward slashes -


I am trying to use the following function from my dashdate 2013-12-11 to 12/12/11 :

  function convertdate (stringdate) {// Internet Explorer does not like dashes in the date when converting, // hence daimrags for year, month and day = / [^ -] * ) - ([^ -] *) - ([^ -] *) /; Var Detroxensonsult = String Date. Match (Detroegs); Var Detroitlecht; Var Stringdate Result = ""; // Try both Firefox and Internet Explorer to create a new date in {dateResult = new date (Detroitze Results [2] + "+" + Detroit Result [3] + "/" + Detrox Result [1]) ; } // If there is an error, hold and try setting a date result using a simple conversion catcher (error) {DateResult = new date (stringdate); } // format to see the string descriptor correctly = date = (DateResult.getMonth () + 1) + "/" + (DateResult.getDate (+ 1) + "/" + (DateResult.getFullYear ()) ; Console.log (StringDateResult); Return Stringent Result; }   

As a test, I pass var myDate = '2013-12-11' and log out before and after the function but The format remains the same? Anyone can say that why am I being wrong with this?

Here is a test jsFiddle :

The function is working, as expected by returning date / value to the expected keyword date (mind).

Your problem looks like your logging

  var myDate = '2013-12-11'; Console.log ('first', myDate); // 2013-12-11 Convert Date (Modet); Console.log ('later', myDate); // 2013-12-11   

If your function returns a value, then the conversion date is returning only and nothing is done and only after logging on your console Returning back on the same date back already.

If you change your console log

  console.log ('after', convertDate (myDate)); // 2013-12-11   

You will get the expected results, or set a new value to myDate

  myDate = convertDate (myDate); Console.log ('later', myDate); // 2013-12-11    

No comments:

Post a Comment