We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
new Date()
new Date(2017,8) //月份从零开始,小一月 new Date(2017,4) //2017-5
var date = new Date(2017,9,3,14,57,18) //2017-10-3 14:57:18 date.getFullYear() //2017 date.getMouth() //9 date.getDate() //3 date.getHours() //14 date.getMinutes //57 date.getSeconds() //18 var date = new Date(); alert('今天是' + date.getFullYear() + '年' + (date.getMonth() + 1) + '月' + date.getDate() + '日'); alert('现在是北京时间' + date.getHours() + '点' + date.getMinutes() + '分' + date.getSeconds() + '秒');
我们希望得到的时间是看的简单的,这样的(2017-10-3 14:57:18)但是在浏览器上的到的结果是这样的
这样的(2017-10-3 14:57:18)
var date = new Date(2017,9,3,14,57,18) date Tue Oct 03 2017 14:57:18 GMT+0800 (中国标准时间)
function padding(number){ return number < 10 ? '0' + number : '' + number; } function format(date) { return date.getFullYear() + '-' + padding(date.getMonth() + 1) + '-' + padding(date.getHours()) + ':' + padding(date.getMinutes()) + ':' + padding(date.getSeconds()); } var date = new Date(); alert(date); //Fri Sep 01 2017 11:24:40 GMT+0800 (中国标准时间) alert(format(date)); //2017-09-01 11:24:40
var date = new Date(2017,9,3,14,57,18) //2017-10-3 14:57:18 date.setFullYear(2050) //2050-10-3 14:57:18 date.setMouth(11) //2050-12-3 14:57:18 date.setDate(16) ///2050-12-16 14:57:18
如果是
date.setDate(35) //2017-11-4,自动计算
function getDays(year, month){ var date = new Date(year, month, 0); return date.getDate(); } alert('2001年2月有' + getDays(2001, 2) + '天。'); alert('2001年3月有' + getDays(2001, 3) + '天。');
var date = new Date(2017,9,3,14,57,18) date.getTime() //1507013838000 距1970-1-1 00:00:00的毫秒数
new Date(1507013838000) date.getTime(1507013838000)
The text was updated successfully, but these errors were encountered:
No branches or pull requests
创建日期
date.getXXX()
格式化
date.setXXX()
求天数?
Date -> Number
Number -> Date
The text was updated successfully, but these errors were encountered: