在JavaScript中获取当前UTC日期 (Getting current UTC date in JavaScript)
To get the current UTC date in JavaScript, we need to use three library functions of Date class,
要在JavaScript中获取当前UTC日期 ,我们需要使用Date类的三个库函数,
Date getDate() Method – It returns current UTC date (day of the month)
Date getDate()方法 –返回当前UTC日期(每月的某天)
Date getMonth() Method – It returns current UTC month of the year
Date getMonth()方法 –返回一年中当前的UTC月份
Date getFullYear() Method – It returns UTC current year in 4 digits format
Date getFullYear()方法 –以4位数字格式返回UTC当前年份
Note: To call these functions, we need to create an object to the Date class using Date class constructor.
注意:要调用这些函数,我们需要使用Date类的构造函数为Date类创建一个对象。
Examples:
例子:
Date class constructor:
var dt = new Date();
Function calls:
dt.getUTCDate();
dt.getUTCMonth()+1;
dt.getUTCFullYear();
Output:
8
3
2019
JavaScript code to get the current UTC date in Date / Month / Year format
JavaScript代码以日期/月/年格式获取当前UTC日期
<html>
<head><title>JavaScipt Example</title></head>
<body>
<script>
var dt = new Date(); //Date constructor
var dd = dt.getUTCDate();
var mm = dt.getUTCMonth()+1;
var yy = dt.getUTCFullYear();
//printing date
document.write("Current UTC date is= " + dd + "/" + mm + "/" + yy + "<br>");
</script>
</body>
</html>
Output
输出量
Current UTC date is= 8/3/2019