js的内置对象------Data

Date:

1:js中用于日期和时间处理的一个对象。

2:在计算机科学中,以1970年1月1日,0时0分0秒 的标准世界时,格林威治时间。为时间原点

3:Date 作为构造函数使用,创建日期对象。

new Date(): 创建以当前系统时间为日期时间的事件对象

typeof new Date() === "object"

补充:两个日期对象可以进行减操作。返回两个日期对象的时间的差值,毫秒返回

4:作为工具函数使用

Date() : 返回的是当前系统时间的字符串表示形式。

5:提供了一些静态函数。

Date.now(): 返回当前系统时间距离时间原点的毫秒的时间差。number类型。

Date.parse(str):返回实参字符串表示的日期时间原点的毫秒的时间差。 number类型。

扩展:

厘秒(centisecond)是比秒小而且比毫秒大的单位,是一秒的百分之一(0.01秒),简称cs。

毫秒(millisecond)是一种较为微小的时间单位,是一秒的千分之一(0.001秒),简称ms。

微秒(microsecond)即百万分之一秒(10的负6次秒),简称μs。

纳秒(nanosecond)即一秒的10亿分之一(10的负9次秒),简称ns,又名“毫微秒”,

皮秒(picosecond)即纳秒的千分之一(10的负12次方秒),简称ps,又名“微微秒”,

普朗克时间 为10的负43次秒,是理论上可观测的最短时间。

6:Date对象还提供了大量的实例函数,用于操作日期对象。

实例函数分为三大类:

to类:将日期对象转换为各种形式的字符串对象

get类:得到当前日期的各种具体的属性值的。

set类:设置日期对象的具体的属性值

注意点(特别重要):

月份和星期几都是0序的

月份取值范围[0-11]

星期取值范围[0-6]依次 对应 周日 到 周六。

附录:

//Date 作为构造函数使用,创建日期对象。
var date = new Date();
console.log (typeof date);//object
console.log (date.toString());
console.log (date);
//创建指定日期的日期对象
var date = new Date("2020-12-12 12:12:12");
console.log (date);
var date = new Date("2020/12/12 12:12:12");
console.log (date);
var date = new Date("2020/12/12");
console.log (date);
//TODO 月份会进行 +1 操作
//实参数据依次为 年月日,时分秒
var date = new Date(2020,2,12,12,12,12);
console.log (date);

console.log (new Date()-new Date("2021-1-5"));

//实参为和时间原点的毫秒的时间差,得到对应的时间差的日期对象
var date = new Date(1500003213323);
console.log (date.toLocaleString());

// 作为工具函数使用
console.log (typeof Date());//string
console.log (Date());

// 提供了一些静态函数。
console.log (typeof Date.now());//number
console.log (Date.now());

console.log (Date.parse("2021-1-6 10:25:12"));

// Date对象还提供了大量的实例函数,用于操作日期对象。
//to
var date = new Date();
console.log (date.toString());
console.log (date.toLocaleString());
console.log (date.toLocaleDateString());
console.log (date.toLocaleTimeString());
console.log (date.toUTCString());
// console.log (date.toISOString());

console.log ("----------");
//get
console.log (date.getFullYear());//2021 年
console.log (date.getMonth());//0 月份 (0~11)
console.log (date.getDate());//6 日
//getDay() 方法可返回一周(0~6)的某一天的数字。
console.log (date.getDay());//3

console.log (date.getHours());//10
console.log (date.getMinutes());//38
console.log (date.getSeconds());//59
console.log (date.getMilliseconds());//555
console.log (date.getTime());// 当前日期对象距离时间原点的时间差,毫秒。
//getTimezoneOffset() 方法可返回格林威治时间和本地时间之间的时差,以分钟为单位。
console.log (date.getTimezoneOffset());//-480  

//set
date.setDate(10);
console.log (date.toLocaleString());
console.log (date.getDay());//0

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值