Does javascript call system time function?

PHPz
Release: 2023-05-16 10:59:37
Original
475 people have browsed it

Yes, JavaScript has a built-in Date object that can be used to get the current system time. Here are a few examples:

  1. Get the current date and time:
var currentDate = new Date();
console.log(currentDate);
Copy after login

Output:

Tue Jun 15 2021 09:57:31 GMT+0800 (China Standard Time)
Copy after login
  1. Get the current date:
var currentDate = new Date();
var year = currentDate.getFullYear();
var month = currentDate.getMonth() + 1;
var day = currentDate.getDate();
console.log(year + "-" + month + "-" + day);
Copy after login

Output:

2021-6-15
Copy after login
  1. Get the current time:
var currentDate = new Date();
var hours = currentDate.getHours();
var minutes = currentDate.getMinutes();
var seconds = currentDate.getSeconds();
console.log(hours + ":" + minutes + ":" + seconds);
Copy after login

Output:

9:57:31
Copy after login

It should be noted that the Date object returns The time is based on the local time of the user's computer. If you need to get the server time, you need to send an AJAX request to the server and get the time in its response.

The above is the detailed content of Does javascript call system time function?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template