javascript中的Data()对象
关于月份的英文
一月 Jan. January
二月 Feb. February
三月 Mar. March
四月 Apr. April
五月 May. May
六月 Jun. June
七月 Jul. July
八月 Aug. August
九月 Sept. September
十月 Oct. October
十一月 Nov. November
十二月 Dec. December
在JS中使用Date对象来表示一个时间,其中Date()为一个构造函数
如果直接使用构造函数创建一个Date对象,则会封装为当前代码执行时间
1、四种初始化日期格式
new Date();
new Date(value);
new Date(dateString);
new Date(year, monthIndex [, day [, hours [, minutes [, seconds [, milliseconds]]]]]);
2、getDate() 获取当前时间对象是几号
var today = new Date()
var today2 = new Date("October 13, 1975 11:13:00")
var today3 = new Date(79,5,24)
var today4 = new Date(79,5,24,11,33,0)
console.log(today.getDate())
console.log(today2.getDate())
console.log(today3.getDate())
console.log(today4.getDate())
3、getDay() 获取当前时间对象时周几 ,0表示周日
var today = new Date()
console.log(today.getDay())
4、getMonth() 获取当前日期对象是几月 0 - 11
var today = new Date()
console.log(today.getMonth())
5、getFullYear() 获取当前日期对象的年份
var today = new Date()
console.log(today.getFullYear())
6、getTime()获取当前时间戳
var today = new Date()
console.log(today.getTime())
7、setTime() 方法以毫秒设置 Date 对象。
var today= new Date()
today.setTime(77771564221)
console.log(today)
8、setFullYear() 方法用于设置年份。
var today= new Date()
today.setFullYear(1992)
console.log(today)