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.
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.
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
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;
};