JS内置对象Math 和Date

一.内置对象Math
常量

 Math.PI,   Math.E,  Math.LN2,  Math.LN10,  Math.LOG2E,  
 Math.LOG10E,  Math.SQRT2(根号2)

成员函数:

绝对值   Math.abs(-10);返回10;
四舍五入:Math.round(1,3);
取整:向下取整Math.floor() ;  向上取整:Math.ceil();
指数和对数 e:Math.exp();    Math.log();
任意数的指数:Math.pow(2,3);  
根号:Math.sqrt();

求最大值最小值

Math.max(1,2,3.....); 
Math.min(1,2,3....)

随机值0~1之间的 平均分布的小数

Math.random();

二.内置对象Date
1.内置对象Date,表示日期和时间

		var d = new Date();
		console.log(d);//输出结果为目前的标准时间

2.巨大的正整数,从1970年1月1日0点以来,毫秒数

	console.log(d.getTime());//输出结果为一个以毫秒计算的整数时间。

3.setFullYear 设定年月(0 -11代表1~12)日

		var d = new Date();
		d.setFullYear(2020,4,1);
		console.log(d);	//输出 May 01 2020 12:13:18

4.构造函数设定年月日

		var d2 = new Date(2020,4,1);
		console.log(d2);//输出 May 01 2020 00:00:00

5.格林尼治时间和UTC协调世界时间

console.log(d.toUTCString());// 输出01 May 2020 04:15:17 与标准时间相差8个小时

6.设定年,setFullYear

		d.setFullYear(2020);

7.获得年getFullYear(),获得月getMonth();获得日getDate();获得星期getDay()

		console.log(d.getFullYear());  // 输出2020
		console.log(d.getMath()+1);    // 输出5
		console.log(d.getDate());      // 输出1
		console.log(d.getDay());       // 输出5

8.获得毫秒数

		var s= d.getTime();

9.克隆

		var d2 = new Date(d);
		console.log(d2);

10.获得小时,分钟,秒

		console.log(d.getHours());
		console.log(d.getMinutes());
		console.log(d.getSeconds());

11.Date 格式化

		//   日期格式化
		console.log(d.toDateString());  //输出Fri May 01 2020
		console.log(d.toLocaleDateString()); //输出2020/5/1

11.时间格式化

		console.log(d.toTimeString());   //输出12:22:36
		console.log(d.toLocaleTimeString());  //输出 下午12:22:36
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值