javascript
在JavaScript中以日期/月/年格式获取当前日期
在JavaScript中獲取當(dāng)前日期 (Getting current date in JavaScript)
To get the current date in JavaScript, we need to use three library functions of Date class,
要在JavaScript中獲取當(dāng)前日期 ,我們需要使用Date類的三個(gè)庫(kù)函數(shù),
Date getDate() Method – It returns current date (day of the month)
Date getDate()方法 –返回當(dāng)前日期(每月的某天)
Date getMonth() Method – It returns current month of the year
Date getMonth()方法 –返回一年中的當(dāng)前月份
Date getFullYear() Method – It returns current year in 4 digits format
Date getFullYear()方法 –以4位數(shù)字格式返回當(dāng)前年份
Note: To call these functions, we need to create an object to the Date class using Date class constructor.
注意:要調(diào)用這些函數(shù),我們需要使用Date類的構(gòu)造函數(shù)為Date類創(chuàng)建一個(gè)對(duì)象。
Examples:
例子:
Date class constructor:var dt = new Date();Function calls:dt.getDate();dt.getMonth()+1;dt.getFullYear();Output:432019JavaScript code to get the current date in Date / Month / Year format
JavaScript代碼以日期/月/年格式獲取當(dāng)前日期
<html> <head><title>JavaScipt Example</title></head><body> <script>var dt = new Date(); //Date constructor var dd = dt.getDate();var mm = dt.getMonth()+1;var yy = dt.getFullYear();//printing datedocument.write("Current date is= " + dd + "/" + mm + "/" + yy + "<br>"); </script> </body> </html>Output
輸出量
Current date is= 4/3/2019翻譯自: https://www.includehelp.com/code-snippets/get-current-date-in-date-month-year-format-in-javascript.aspx
總結(jié)
以上是生活随笔為你收集整理的在JavaScript中以日期/月/年格式获取当前日期的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 没有值的json字符串_Java中具有原
- 下一篇: 如何在React JS组件和React