How to convert 10/jan/2010 to 10/01/2010 using JavaScript or jQuery
Kindly help me
How to convert 10/jan/2010 to 10/01/2010 using JavaScript or jQuery
Kindly help me
There's no month string representation like that in javascript, so you have to define that yourself for starters:
var months = {jan: '01', feb: '02', mar: '03', apr: '04', may: '05', jun: '06',
jul: '07', aug: '08', sep: '09', oct: '10', nov: '11', dec: '12'};
Now, given a date
var datestring = '10/jan/2010';
You need to first filter out your month segment:
var monthpart = datestring.split('/')[1];
And then do a simple replace:
var datestring = datestring.replace(monthpart, months[monthpart]);
Take a look here. http://github.com/vitch/jquery-methods/raw/master/date.js Its cool and it does pretty good job for all the possibilities and error handling is also pretty good.
var d1 = Date.parse('10/jan/2010');
alert(d1.toString('dd/mm/yyyy'));