2

Iam trying to convert the format of date from dd-MM-yyyy into yyyy-MM-dd using date.js java script libray .. for that I used following code

var myDate = Date.parse("15-09-2014");
DateFormat = myDate.toString('yyyy-MM-dd');
alert(DateFormat );

so when alerting DateFormat i got the correct output as 2014-09-15 . But when i am trying to format a date in which the day is below 13 , i got the output in which the day and date positions interchanged... for example when i give input as "12-09-2014", i got the result as 2014-12-09....but am expecting 2014-09-12... Can anybody help me please...?

0

1 Answer 1

1

You can use parseExact to define your format.

var myDate = Date.parseExact("11-09-2014", "d-M-yyyy");
DateFormat = myDate.toString('yyyy-MM-dd');
alert(DateFormat);

See http://jsfiddle.net/mf4v6wjd/1/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.