Wed, 03 Aug 2011 15:49:22 -0开发者_如何学JAVA700
Thanks in advance!
PeterSimilar questions have been asked before For example How to convert dateTime format in javascript which links to the useful http://blog.stevenlevithan.com/archives/date-time-format
To answer this in plain JS, here is something that will give you the date in local time, i.e. your -0700 becomes +0200 on my computer
http://jsfiddle.net/mplungjan/HMkLd/
function getMicroformat(date) {
var d = date.toString();
var parts = d.split(" ");
return parts[0]+", "+
parts[2]+" "+
parts[1]+" "+
parts[3]+" "+
parts[4]+" "+
parts[5].replace(/[A-Z]/g,"");
}
// OR
function getMFReg(d) {
var reg = /(\D{3}) (\D{3}) (\d{2}) (\d{4}) ([:|\d]{8}) \D{3}([+|-|\d]{3})/
return d.toString().replace(reg,"$1, $3 $2 $4 $5 $6")
}
var str = "Wed, 03 Aug 2011 15:49:22 -0700";
var d = new Date(str);
document.write(str +"<br>=><br>"+getMicroformat(d));
document.write("<br>=><br>"+getMFReg(d));
use this,
var d1=new Date();
d1.toString('yyyy-MM-dd'); //returns "2009-06-29"
d1.toString('dddd, MMMM ,yyyy') //returns "Monday, June 29,2009"
you can set your format which you want
精彩评论