Date 对象

Date 对象:
作用:用于处理日期和时间。
创建:
var date = new Date(); // 返回当前系统时间所表示的日期时间对象
var date = new Date(milliseconds); // 返回是日期时间是相对 1970-1-1 0:0:0 (UTC时间)以来的毫秒计算时间值
var date = new Date(“yyyy-MM-ddTHH:mm:ss”); // 返回字符串表示的日期时间对象
var date = new Date(year, month, date, hour, minute, second, millisecond); // 单独传递年月日时分秒毫秒值,month取值是 0~11,表示1~12月
API:
方法:
获取:
getFullYear() – 完整的4位年份
getMonth() – 月份,返回的是 0~11
getDate() – 日期
getDay() – 星期,返回的是 0~6
getHours() – 小时
getMinutes() – 分钟
getSeconds() – 秒
getMilliseconds() – 毫秒
设置:
setFullYear() – 完整的4位年份
setMonth() – 月份,返回的是 0~11
setDate() – 日期
setHours() – 小时
setMinutes() – 分钟
setSeconds() – 秒
setMilliseconds() – 毫秒

    毫秒(距1970-1-1 0:0:0):
            getTime() -- 返回距1970-1-1 0:0:0以来的毫秒值
            setTime() -- 根据距1970-1-1 0:0:0以来的毫秒值设置日期时间对象
            Date.now()  -- (ES5)返回距1970-1-1 0:0:0以来的毫秒值
            Date.parse(dateStr) -- 将日期时间字符串解析转换为表示时间的毫秒值

        转换:
            toString()
            toUTCString()
                toLocaleString()
                toDateString()
                toTimeString()

猜你喜欢

转载自blog.csdn.net/qq_37321858/article/details/82191437