javascript中的Data()对象

本文详细介绍了JavaScript中Date对象的使用方法,包括不同日期格式的初始化方式、如何获取具体日期信息如日期、星期、月份和年份等,以及如何设置日期时间。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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)
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值