Javascript Convert Date from short format to Long format -
i using following code:
var date="may-02-2012"; var startdate = date; var tmp = startdate.split('-'); tmp.splice(1, 0, ','); var convertedstartdate = new date(tmp.join(' ')); var month = convertedstartdate.getmonth() + 1 var day = convertedstartdate.getdate(); var year = convertedstartdate.getfullyear(); var shortstartdate = ('0' + day).slice(-2) + "-" + ('0' + month).slice(-2) + "-" + ('0' + year).slice(-2); return(shortstartdate); the code above allows convert may-02-2012 02-05-12
however, need convert 02-05-12 may-02-2012
but can't work out..
no hard provided format specified. following doesn't testing if format wrong, might awry. function if give wrong format.
var s = '02-05-12'; function toweirddate(s) { var months = 'jan feb mar apr may jun jul aug sep oct nov dec'.split(' '); var bits = s.split('-'); return months[--bits[1]] + '-' + bits[0] + '-20' + bits[2]; } alert(toweirddate(s)); // may-02-2012
Comments
Post a Comment