日期:2014-05-16 浏览次数:20364 次
// date.js
// Illustrates the use of the Date object by
// displaying the parts of a current date and
// using two Date objects to time a calculation
// Get the current date
alert("Start date.js");
var today = new Date();
// Fetch the various parts of the date
var dateString = today.toLocaleString();
var day = today.getDay();
var month = today.getMonth();
var year = today.getFullYear();
var timeMilliseconds = today.getTime();
var hour = today.getHours();
var minute = today.getMinutes();
var second = today.getSeconds();
var millisecond = today.getMilliseconds();
// Display the parts
document.write(
"Date: " + dateString + "<br />",
"Day: " + day + "<br />",
"Month: " + month + "<br />",
"Year: " + year + "<br />",
"Time in milliseconds: " + timeMilliseconds + "<br />",
"Hour: " + hour + "<br />",
"Minute: " + minute + "<br />",
"Second: " + second + "<br />",
"Millisecond: " + millisecond + "<br />");
var t ="2014-05-03T 20:50:33";
function format_t(t){
var d=new Date(),b;
if(b=t.match(/\d+/g)){
return d.getFullYear()==b[0] && (d.getMonth()+1)==b[1] && d.getDate()==b[2] ? b[3]+":"+b[4] : b[1]+"-"+b[2];
}else{
return "";
}
}
console.log(format_t(t));
var t ="2014-05-03T 20:50:33";
function format_t(t){
var d=new Date(),b=t.m