js 获取当前时间

js 获取当前时间 年月日

    var date = new Date();
    date.getYear(); //获取当前年份
    date.getFullYear(); //获取完整的年份(4位)
    date.getMonth(); //获取当前月份(0-11,0代表1月)
    date.getDate(); //获取当前日(1-31)
    date.getDay(); //获取当前星期X(0-6,0代表星期天)
    date.getTime(); //获取当前时间(从1970.1.1开始的毫秒数)
    date.getHours(); //获取当前小时数(0-23)
    date.getMinutes(); //获取当前分钟数(0-59)
    date.getSeconds(); //获取当前秒数(0-59)
    date.getMilliseconds(); //获取当前毫秒数(0-999)
    date.toLocaleDateString(); //获取当前日期
    date.toLocaleTimeString(); //获取当前时间
    date.toLocaleString(); //获取日期与时间

如下图:

原文地址:https://www.cnblogs.com/lwming/p/10933588.html