js日期总结

获取当前时间

 var date = new Date();
    console.log(date);
**1.中国格式时间        //传入一个字符串参数**
  var date = new Date("2012-12-2 8:25:40");
    console.log(date);

    var date = new Date("2012/10/2 8:25:40");
    console.log(date);

2.国外格式时间 //传入多个参数
//月份 0-11 星期0-6

 var date = new Date(2000, 0, 1, 8, 25, 40);   //1月
 console.log(date);
 var date = new Date(2000, 1, 1, 8, 25, 40);   //2月  
 console.log(date);
 //......

数值超出,向下换算

  var date = new Date(2019, 12, 9, 8, 15); // =>(2020,0,9);   国外
  console.log(date);

  var date = new Date(2019, 12, 32, 9, 8, 15);//    =>(2020,0,32) =>(2020,1,1) 国外   
  console.log(date);

如果数值为负值,向上换算

	 var date = new Date(2019, -1, 1, 9, 8, 15); // => (2018,11,1);
   	 console.log(date);
  	 var date = new Date(2019, -1, 0, 9, 8, 15); // => (2018,11,0) =>(2018,10,30);
  	 console.log(date);

获取毫秒

   var date = new Date();
    var ms = date * 1;      // 遇到  -  *  /  都转化成毫秒
    console.log("毫秒", ms);

    var ms = date.valueOf(); //获取毫秒
    console.log(ms);

    var month = date.getMonth();    //获取的是外国月份
    console.log(month);

    var date1 = date.getDate();
    console.log(date1);
    //...... date.getDay() ..date.getDay() 

赋值

var date = new Date();
date.setMonth(0);  // 国外1月
console.log(date);
//.... setDate() 赋值日期

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值