目录
1、Date日期对象
标准对象
typeof 132
'number'
typeof '123'
'string'
typeof true
'boolean'
typeof NaN
'number'
typeof []
'object'
typeof {}
'object'
typeof Math.abs
'function'
typeof undefined
'undefined'
基本使用
'use strict';
// 当前打印的时间
let now = new Date();
now.getFullYear();//年 2022
now.getMonth();//月 0-11
now.getDate();//日
now.getDay();//星期几 0-6 0:星期天
now.getHours();//时
now.getMinutes();//分
now.getSeconds();//秒
now.getTime();//时间戳 全世界统一 1970 1.1 00:00:00 毫秒数 1664273598303
console.log(new Date(1664273598303));//时间戳转为时间
转换
now = new Date();
Tue Sep 27 2022 18:32:00 GMT+0800 (中国标准时间)
now.toLocaleDateString()
'2022/9/27'
now.toGMTString()
'Tue, 27 Sep 2022 10:32:00 GMT'
2、JSON对象
json是什么?
-
JSON(JavaScript Object Notation, JS 对象简谱) 是一种轻量级的数据交换格式。
-
简洁和清晰的层次结构使得 JSON 成为理想的数据交换语言。
-
易于人阅读和编写,同时也易于机器解析和生成,并有效地提升网络传输效率。
- 早起,所有的数据传输习惯使用xml文件。
- 在JavaScript一切皆为对象,任务js支持的类型都可以用json来表示
格式:
-
对象都用{ }
-
数据都用[ ]
-
所有的键值对都是用key:value
json字符串和js对象的转化
(1)如果是没用json
let user = {
name: "山姆",
age: 3,
sex: "male"
}
(2)如果是使用了json
let user = {
name: "山姆",
age: 3,
sex: "male"
}
// 对象转换成json字符串 {"name":"山姆","age":3,"sex":"male"}
let jsonUser = JSON.stringify(user)
(3)转换
let user = {
name: "山姆",
age: 3,
sex: "male"
};
// 对象转换成json字符串 {"name":"山姆","age":3,"sex":"male"}
let jsonUser = JSON.stringify(user)
// json字符串转化为对象,参数为json字符串
let obj = JSON.parse('{"name": "山姆", "age": "3", "sex": "male"}')
json和js对象的区别:
let obj = {a:'a',b:'b'};
// 外面要用''
let json = '{"a":"a","b":"b"}';
3、Ajax
-
原生的js写法 xhr异步请求
-
jQuery封装好的方法 ${"#name"}.ajax("")
-
axios请求