Skip to content

Instantly share code, notes, and snippets.

@dailc
Last active May 26, 2017 03:33
Show Gist options
  • Save dailc/a3349d341e78d867e2578caea2d70997 to your computer and use it in GitHub Desktop.
Save dailc/a3349d341e78d867e2578caea2d70997 to your computer and use it in GitHub Desktop.
[JS日期操作] JS中的日期操作,如时间戳等 tags:date,timestamp
## 获取时间戳的几种方法
```
var timestamp = Date.parse(new Date());
// 结果例如: 1280977330000(毫秒变为了000显示)
```
```
var timestamp = (new Date()).valueOf();
// 1280977330748
```
```
var timestamp=new Date().getTime();
// 1280977330748
```
## 两个时间的简单比较
```
var time = new Date('2017-05-26 00:00:00');
var time2 = new Date('2017-05-27 00:00:00');
console.log(time.valueOf() > time2.valueOf()); // false
console.log(time.valueOf() == time2.valueOf()); // false
console.log(time.valueOf() < time2.valueOf()); // true
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment