Datetime conversion in JavaScript or jQuery
How to convert 10/jan/201开发者_StackOverflow中文版0 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]);
Try date.js we use it in our web app.
A warning though... the localisation architecture of the lib makes it a pain to load dynamically.
And be sure to fetch the svn version, there are(was?) some bugs in the downloadable version.
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'));
精彩评论