[Solved] Jquery: How do i convert 1111-yyyy-mm-dd into 1111-mm/dd/yyyy


If you just want to convert without any date validations you can do it with string functions. Or if you want to use date functions, apply it only to that part of the string after splitting the string. Nothing fancy.

Use normal Date constructor (year,[month,[date...]]) when creating Date objects, passing non-standard formats is not recommended as the implementations are browser dependant.

var string = "1111-2016-10-26";
var a = string.split('-');
var number = a[0];
var date = a[2] + "https://stackoverflow.com/" + a[3] + "https://stackoverflow.com/" + a[1];
console.log(number + '-' + date);
var string = '1111-2010-10-11';
var a = string.split('-').map(Number);
var date = new Date(a[1], a[2] - 1, a[3]);
var dateString = ((date.getMonth() + 1) + "https://stackoverflow.com/" + date.getDate() + "https://stackoverflow.com/" +  date.getFullYear());

console.log(a[0]+ '-' + dateString);

3

solved Jquery: How do i convert 1111-yyyy-mm-dd into 1111-mm/dd/yyyy