//Date对象用来表示一个时间
// 如果直接使用构造函数创建一个Date对象,会封装为当前代码执行时间
var d = new Date();
console.log(d)
// 日期格式 月/日/年 时:分:秒
var d2 = new Date("1/1/2000 1:11:11")
console.log(d2)
// getTime()获取时间戳
var date = d2.getTime()
console.log(date)
// Date.now()获取当前时间戳
date = Date.now()
console.log(date)
包装类
// js中为我们提供了三个包装类,这三个包装类可将基本数据类型转换为对象Object
// String()
// Number()
// Boolean()
var num = new Number(3);
console.log(typeof num)
num.name = "test"
console.log(num)
// 在实际应用中不会使用基本数据类型的对象,如下
var b = new Boolean(false)
if(b){
console.log("运行")
}
// 方法和属性只能添加给对象,不能添加给基本数据类型
// 对基本数据类型的值去调用属性和方法时,浏览器会将其临时使用包装类转换为对象
var s = 123;
s = s.toString();
// 没有报错,说明转换为对象
s.name = "test";
// 输出undefined,说明转换为了基本数据类型
console.log(s.name)