4.入門第四課:javascript日付の対象
1055 ワード
js , , , :
<script type="text/javascript">
var d=new Date();//
//
document.write(d.getFullYear());
document.write(d.getMonth());
document.write(d.getDate());
document.write(d.getHours());
document.write(d.getMinutes());
document.write(d.getSeconds());
document.write(d.getMilliseconds());
//
var d1=new Date();
d1.setFullYear(1980);
d1.setMonth(10);
d1.setDate(10);
d1.setHours(9);
d1.setMinutes(10);
d1.setSeconds(10);
d1.setMilliseconds(100);
// , , true
document.write(d>d1);
</script>
以下は日付の実用関数です.//
function dtoS(d){
var s="";
s+=(d.getFullYear()+" ");
s+=((d.getMonth()+1)+" ");
s+=(d.getDate()+" ");
s+=(" "+d.getHours()+":");
s+=(" "+d.getMinutes()+":");
s+=(" "+d.getSeconds());
return s;
}
var d=new Date();
var s=dtoS(d);// :2013 9 22 10: 37: 59