JavaScript getUTCDay 函数

JavaScript getUTCDay 函数是 Date Functions 之一,它根据世界时返回给定日期的星期几。星期几从 0 开始到 6 结束,其中 0 代表星期日,6 代表星期六。getUTCDay 函数的语法是

 Date.getUTCDay()

在这里,我们使用 getUTCDay 从当前日期和时间返回星期几。

<!DOCTYPE html>
<html>
<head>
    <title> JS </title>
</head>
<body>
    <h1> Example </h1>
<script>
  var dt = Date();  
  document.write("Date and Time : " + dt);
  document.write("UTC Day : " + dt.getUTCDay());
</script>
</body>
</html>
Example

Date and Time: Mon Nov 05 2018 10:37:44 GMT+0530 (Indian Standard Time)
UTC Day : 1

在这个 JavaScript get UTC Day 示例中,我们显示了自定义日期的星期几。

<!DOCTYPE html>
<html>
<head>
    <title> JavaScript Get UTC Day Function </title>
</head>
<body>
    <h1> JavaScriptgetUTCDayFunctionExample </h1>
<script>
  var dt = Date("April 1, 2016 10:14:22");
  document.write("Date and Time : " + dt);
  document.write("UTC Day using getUTCDay : " + dt.getUTCDay());
</script>
</body>
</html>
getUTCDay Function Example