美文网首页
时间对象

时间对象

作者: bf619faf3b0e | 来源:发表于2018-09-08 16:38 被阅读0次

    创建时间对象:

    var date=new Date() --返回当前系统时间所表示的日期时间对象.

    var date = new Date(milliseconds);--相对于1979.1.1 8:0:0 的时间日期对象;

    var date = new Date("YYYY-MM-DDTHH:mm:ss")--以字符串形式赋值时间

    var date = new Date(year,mouth,day,hour,min,sec) --月的取值0~11;

    API:

    获取:

    date.getFullYear()--得到完整的四位数年份

    date.getMonth();--得到月份 0~11

    date.getDate();

    date.getDay();--获取星期 0~6

    date.getHours();--得到整时

    date.getMinutes();--分

    date.getSeconds();--秒

    date.getMilliseconds()--毫秒

    设置:

    date.setFullYear()--得到完整的四位数年份

    date.setMonth();--得到月份 0~11

    date.setDate();--得到日期 0~30

    date.setHours();--得到整时

    date.setMinutes();--分

    date.setSeconds();--秒

    date.setMilliseconds()--毫秒

    Date.now();-- (ES5)返回距1970-1-1 8:0:0 以来的毫秒值

    Date.parse(); -- 将日期时间字符串解析转换为表示时间的毫秒值

    转换:

    date.toString()

    date.toUTCString()

    date.toLocaleString()

    date.toDateString()

    date.toTimeString()

    date.toISOString()-- YYYY-MM-DDTHH:mm:ss.sssZ

    date.toJSON()-- YYYY-MM-DDTHH:mm:ss.sssZu

    相关文章

      网友评论

          本文标题:时间对象

          本文链接:https://www.haomeiwen.com/subject/nmqlgftx.html