Last active
May 26, 2017 03:33
-
-
Save dailc/a3349d341e78d867e2578caea2d70997 to your computer and use it in GitHub Desktop.
[JS日期操作] JS中的日期操作,如时间戳等 tags:date,timestamp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 获取时间戳的几种方法 | |
``` | |
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