Home >Web Front-end >Front-end Q&A >Does javascript call system time function?
Yes, JavaScript has a built-in Date object that can be used to get the current system time. Here are a few examples:
var currentDate = new Date(); console.log(currentDate);
Output:
Tue Jun 15 2021 09:57:31 GMT+0800 (China Standard Time)
var currentDate = new Date(); var year = currentDate.getFullYear(); var month = currentDate.getMonth() + 1; var day = currentDate.getDate(); console.log(year + "-" + month + "-" + day);
Output:
2021-6-15
var currentDate = new Date(); var hours = currentDate.getHours(); var minutes = currentDate.getMinutes(); var seconds = currentDate.getSeconds(); console.log(hours + ":" + minutes + ":" + seconds);
Output:
9:57:31
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!