Home > Web Front-end > JS Tutorial > body text

Introduction and examples of Date methods in JavaScript

不言
Release: 2018-08-09 17:26:40
Original
1376 people have browsed it

This article brings you an introduction and examples of Date methods in JavaScript. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

Date method

console.log(typeof Date);// "function"
Copy after login

Date instance

console.log(typeof new Date());
// "object"
console.log(new Date());
// 获取本机的系统时间;
var time = new Date();
console.log(time.getFullYear());
// 获取时间年;
console.log(time.getMonth())
// 获取时间月 取值范围【0-11】
console.log(time.getDate());
// 获取时间日【1-31】
console.log(time.getDay());
// 获取星期几;【0-6】 星期日是0;
console.log(time.getHours())
// 获取小时数 【0-23】
console.log(time.getMinutes());
// 获取分钟数 【0-59】
console.log(time.getSeconds());
// 获取时间秒【0-59】 console.log(time.getMilliseconds());
// 获取毫秒数【0-999】
console.log(time.getTime());
// 当前时间距离1970-1-1日早上八点的毫秒数;
console.log(Date.now());
// 时间戳:
Copy after login

Related recommendations:

Code implementation of javascript event delegation and code optimization

JS tutorial--Knapsack capacity problem of dynamic programming algorithm

The above is the detailed content of Introduction and examples of Date methods in JavaScript. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!