jdbc setdate_日期setDate()方法以及JavaScript中的示例

jdbc setdate

JavaScript Date setDate()方法 (JavaScript Date setDate() method)

setDate() method is a Date class method, it is used to set the current date (day of the month) to the Date object with a valid date value (between 1 to 31, based on the current month).

setDate()方法是Date类的一种方法,用于将当前日期(一个月中的某天)设置为具有有效日期值(基于当前月份的1到31之间)的Date对象。

Note: Date larger than the last date of the month will be truncated from the starting date, for example, in the March there are 31 days and you set the date value to 33, then it will set to the date as the second day of the month (2 March).

注意:大于月份最后日期的日期将从开始日期开始被截断,例如,在三月有31天,您将日期值设置为33,然后将其设置为该日期的第二天一个月(3月2日)。

Syntax:

句法:

    var dt = new Date();
    dt.setDate(day);

Examples:

例子:

    
    Input/Date class object declaration:
    var dt = new Date();

    Function call to set the date:
    dt.setDate(17);

    Function call to get the date:
    dt.getDate(); 

    Output:
    17

JavaScript code to demonstrate an example of Date.setDate() method

JavaScript代码演示Date.setDate()方法的示例

<html>
<head><title>JavaScipt Example</title></head>

<body>
<script>
	var dt = new Date();
	//getting current date (day of the month)
	var date = dt.getDate();
	//printing
	document.write("date: " + date + "<br>");
	
	//setting date to 17
	dt.setDate(17);
	//getting & printing date again
	date = dt.getDate();
	document.write("date: " + date + "<br>");
	
	//setting invalid date
	//setting date to 33 
	//This is March month, when I am writing this code
	//maximum month in March is 31, thus, 33 will set 
	//date as 2
	dt.setDate(33);
	//getting & printing date again
	date = dt.getDate();
	document.write("date: " + date + "<br>");	
	
</script>
</body>
</html>

Output

输出量

date: 12
date: 17
date: 2

Reference: JavaScript setDate() Method

参考: JavaScript setDate()方法

翻译自: https://www.includehelp.com/code-snippets/date-setDate-method-with-example-in-javascript.aspx

jdbc setdate

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值