JavaScript getDate 函数是 Date 函数之一,可用于从给定日期中返回日期编号。本文将通过一个示例介绍在此编程中如何使用 Get Date。
以下示例将帮助您理解 getDate 函数。在这里,我们使用 getDate 从当前日期时间中返回日期。
<!DOCTYPE html>
<html>
<head>
<title> JFunctions </title>
</head>
<body>
<h1> Example </h1>
<script>
var dt = Date();
document.write("DateTime : " + dt);
document.write("Date : " + dt.getDate());
</script>
</body>
</html>
Example
DateTime: Sat Nov 03 2018 15:34:10 GMT+0530 (Indian Standard Time)
Date : 3
在此 JavaScript 示例中,我们正在从自定义日期时间中提取日期编号。
<!DOCTYPE html>
<html>
<head>
<title> JS </title>
</head>
<body>
<h1> JavaScriptgetDateFunction Example </h1>
<script>
var dt = Date("January 22, 2014 10:09:07");
document.write("Date and Time : " + dt);
document.write("Date from getDate(): " + dt.getDate());
</script>
</body>
</html>
