Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize date output by JavaScript

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to achieve date output by JavaScript". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "JavaScript how to achieve date output" bar!

By default, JavaScript uses the browser's time zone and displays the date as a full-text string:

Tue Apr 02 2019 09:01:19 GMT+0800 (China Standard time)

Later, you will learn more about how to display dates in this tutorial.

Create a Date object

The Date object is created by the new Date () constructor.

There are four ways to create a new date object:

New Date ()

New Date (year, month, day, hours, minutes, seconds, milliseconds)

New Date (milliseconds)

New Date (date string)

New Date ()

New Date () creates a new date object with the current date and time:

Example

Var d = new Date ()

The date object is static. The computer time is ticking, but the date object will not.

New Date (year, month, … )

New Date (year, month, … Creates a new date object with the specified date and time

Seven numbers specify year, month, day, hour, minute, second, and millisecond (in this order):

Example

Var d = new Date (2018, 11, 24, 10, 33, 30, 0)

6 numbers specify year, month, day, hour, minute, second:

Example

Var d = new Date (2018, 11, 24, 10, 33, 30)

5 numbers specify year, month, day, hour and minute:

Example

Var d = new Date (2018, 11, 24, 10, 33)

Four numbers specify the year, month, day and hour:

Example

Var d = new Date (2018, 11, 24, 10)

Three numbers specify the year, month and day:

Example

Var d = new Date (2018, 11, 24)

2 digits specify the year and month:

Example

Var d = new Date (2018, 11)

You cannot omit the month. If only one parameter is provided, it is treated as milliseconds.

At this point, I believe you have a deeper understanding of "JavaScript how to achieve date output", might as well come to the actual operation of it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report