Reformat string containing date with Javascript

one solution without regex:

var expDate="2016-03";
var formatExp = expDate.split('-').reverse().join("https://stackoverflow.com/");
//result is 03/2016
alert('result: ' + formatExp);

var formatExpShort = expDate.substring(2).split('-').reverse().join("https://stackoverflow.com/");
//result is 03/16
alert('result short: ' + formatExpShort);

Leave a Comment