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
翻译自: https://www.includehelp.com/code-snippets/date-setDate-method-with-example-in-javascript.aspx
jdbc setdate