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.
fecha2.value = '2014-01-06'
'01-06-14'
How can I do this? Thanks in advance.
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);
2.1m questions
2.1m answers
60 comments
57.0k users