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

Date object in JavaScript

一个新手
Release: 2017-09-23 10:11:28
Original
1412 people have browsed it


【JavaScript Date Object】


# #Date object

Date object: used to set and get the current time.

Date object methods are divided into two types:

One uses local time; One uses world time UTC (that is, if there is "UTC" in the method), it means World time; (based on 0 degrees longitude).

Get the current time of the system:

var time = new Date();
console.log(time);
获取具体时间(get)
Copy after login

All get methods have UTC acquisition, except getYear()\getTimes( )

Obtain time other than UTC is world time):
get[UTC]FullYear( )——获取年份;
get[UTC]Month( )——获取月份;
get[UTC]Date( )——获取日期;
get[UTC]Day( )——获取星期;
get[UTC]Hours( )——获取小时;
get[UTC]Minutes( )——获取分钟;
get[UTC]Seconds( )——获取秒数;
get[UTC]Milliseconds( )——获取毫秒;
getTime( ):返回Date对象的内部毫秒,这个值没有“UTC”方法;
getTimezoneOffset():返回当前日期的本地表示与UTC表示之间的时间差的值;
getYear( ):返回Date对象的年份值,建议使用get[UTC]FullYear()。
Copy after login
Three ways to set the time

set[UTC]FullYear( )——设置年份;
set[UTC]Month( )——设置月份;
set[UTC]Date( )——设置日期;
set[UTC]Hours( )——设置小时;
set[UTC]Minutes( )——设置分钟;
set[UTC]Seconds( )——设置秒数;
set[UTC]Milliseconds( )——设置毫秒;
setTime( ):使用毫秒格式,设置一个Date对象的值;
setYear( ):设置年份值,建议使用set[UTC]FullYear()。
Copy after login

The above is the detailed content of Date object 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!