Js 日期处理整理(二)_Js 日期时间戳、字符串、时间差

一、js Date对象、时间戳之间转换

1.js Date对象转时间戳

var now = new Date();

//js Date对象转时间戳
var timeKey = now.getTime(); //1605334977352
console.info(timeKey);

2.js 时间戳 转 Date对象

//js 时间戳 转 Date对象
var timeOne = new Date(1605334977352);
console.info(timeOne); //Sat Nov 14 2020 14:22:57 GMT+0800 (中国标准时间)

二、js Date对象、时间字符串之间转换

1.js 字符串转Date对象

//js 时间字符串 转 时间对象
//中文间隔不支持 例如:2020年10月1日
var timeTwo = new Date('2020-10-1');
console.info(timeTwo.toLocaleString()); //2020/10/1 上午12:00:00

var timeThree = new Date('2020-11-1 08:30');
console.info(timeThree.toLocaleString()); //2020/11/1 上午8:30:00

var timeFourth=new Date('2020/12/10 10:15');
console.info(timeFourth.toLocaleString());  //2020/12/1
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值