var now= new Date();
var year=now.getYear();
var month=now.getMonth()+1;
var day=now.getDate();
var hour=now.getHours();
var minute=now.getMinutes();
var second=now.getSeconds();我想让他的月份 日期 时 分 秒 都是两位的输出例如 06 月 04日 21 点 05分 00秒 那种 能实现吗?
var year=now.getYear();
var month=now.getMonth()+1;
var day=now.getDate();
var hour=now.getHours();
var minute=now.getMinutes();
var second=now.getSeconds();我想让他的月份 日期 时 分 秒 都是两位的输出例如 06 月 04日 21 点 05分 00秒 那种 能实现吗?
second=(second>=10?"0"+second:second);
var year=now.getYear();
var month=now.getMonth()+1;
var day=now.getDate();
var hour=now.getHours();
var minute=now.getMinutes();
var second=now.getSeconds();
if(month<10)
{
month="0"+month;
}
if(day<10)
{
day="0"+day;
}
if(hour<10)
{
hour="0"+hour;
}
if(minute<10)
{
minute="0"+minute;
}
if(second<10)
{
second="0"+second;
}
document.write("今天是");
document.write("");
document.write(year);
document.write("年");
document.write(month);
document.write("月");
document.write(day);
document.write("日");
document.write(hour);
document.write("时");
document.write(minute);
document.write("分");
document.write(second);
document.write("秒");
</script>
</body>