-2

I have the following format of date 1.7.2015 19:18 which is date.month.year format.

When I convert it into the date variable it is converting as mm-dd-yy format.

How can I achieve the format of dd-mm-yyyy for the same in JavaScript.

Greg Pettit
  • 10,749
  • 5
  • 53
  • 72
  • This question has been asked countless times. Google it before asking a question man! – jonny Jul 01 '15 at 13:52
  • possible duplicate of [Where can I find documentation on formatting a date in JavaScript?](http://stackoverflow.com/questions/1056728/where-can-i-find-documentation-on-formatting-a-date-in-javascript) – Walter Chapilliquen - wZVanG Jul 01 '15 at 13:52

2 Answers2

0

You can try moment.js @ http://momentjs.com/

You can play around with all sort of date functions. Format & Parse the way you want.

moment().format('MMMM Do YYYY, h:mm:ss a');
will format the current date in this format:
July 1st 2015, 7:25:03 pm

arnabkaycee
  • 1,634
  • 13
  • 26
0

If the date value is being retrieved from an input field then you can do something like this:

Javascript

window.onload = function(){
    var splitted_date = document.getElementById("date").value.split("-"),
        day = splitted_date[1],
        month = splitted_date[0],
        year = splitted_date[2],
        formatted_date = day + "-" + month + "-" + year;
};
Zahid Saeed
  • 1,101
  • 1
  • 8
  • 14