Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change date format using jQuery?

I have a date in a format like this fecha2.value = '2014-01-06', but I want to change the format to this '01-06-14' using jQuery.

How can I do this? Thanks in advance.

like image 949
User1988 Avatar asked Jan 06 '14 09:01

User1988


People also ask

How do I change the date format from YYYY-MM-DD in jQuery?

Re: convert Date from YYYY-MM-DD to MM/DD/YYYY in jQuery/JavaScript. var tempDate = new Date("2021-09-21"); var formattedDate = [tempDate. getMonth() + 1, tempDate.

What is the date format in jQuery?

format = All input formats valid for jQuery. format. date are valid for this method. The defaut format is MM/dd/yyyy HH:mm:ss.

How do I change Datepicker format?

Do one of the following: For a text box control or a date picker control, ensure that the Data type list displays the appropriate data type, and then click Format. For an expression box control, ensure that the Format as list displays the appropriate data type, and then click Format.


1 Answers

You can use date.js to achieve this:

var date = new Date('2014-01-06');
var newDate = date.toString('dd-MM-yy');

Alternatively, you can do it natively like this:

var dateAr = '2014-01-06'.split('-');
var newDate = dateAr[1] + '-' + dateAr[2] + '-' + dateAr[0].slice(-2);

console.log(newDate);
like image 132
Rory McCrossan Avatar answered Oct 04 '22 12:10

Rory McCrossan