JS中Date()

   //JS中的内置对象Date的使用
    //直接输出现时现点时间
 var today=new Date();
 document.write(today);

var today=new Date();
document.write(today.toDateString()+"<br>");//英文格式
document.write(today.toLocaleDateString());//中文格式
/**
* 结果
* Mon Mar 18 2019
2019/3/18
*/
 
document.write(today.toLocaleTimeString()+"<br>");//小时分钟秒
document.write(today.toTimeString());//小时分钟秒
结果:
下午6:44:19
18:44:19 GMT+0800 (中国标准时间)

 

 

    //JS中的内置对象Date的使用
    var today=new Date();
    document.write(today.getFullYear()+"");//获取年份
    document.write(today.getMonth()+1+"");//获取月份
    document.write(today.getDate()+"");//获取日期
    document.write(today.getHours()+"");//获取小时
    document.write(today.getMinutes()+"");//获取分钟
    document.write(today.getSeconds()+"");//获取秒
    document.write("星期"+today.getDay());//获取星期

 

posted @ 2019-03-18 17:30  showTimehzy  阅读(388)  评论(0编辑  收藏  举报