2012年4月30日月曜日

javascriptで現在時刻をyyyymmddhhiissで表示

function getNow(){
  nowtime = new Date();
  yy = nowtime.getYear();
  mm = nowtime.getMonth() + 1;
  dd = nowtime.getDate();
  hh = nowtime.getHours();
  if(hh < 10){hh = "0" + hh;}
  ii = nowtime.getMinutes();
  if(ii < 10){ii = "0" + ii;}
  ss = nowtime.getSeconds();
  if(ss < 10){ss = "0" + ss;}
  if (yy < 2000) { yy += 1900; }
  if (mm < 10) { mm = "0" + mm; }
  if (dd < 10) { dd = "0" + dd; }
    return (yy + "/" + mm + "/" + dd + " " + hh + ":" + ii + ":" + ss);
}
document.write(getNow());
loading...

0 件のコメント:

コメントを投稿