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

What is the method of converting date to timestamp in javascript?

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article introduces the relevant knowledge of "what is the method of converting javascript date to timestamp". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

The method of converting date to timestamp by javascript: 1, using Date function to convert time string into Date type; 2, converting Date type into timestamp type through "date.getTime ()" and other methods.

This article operating environment: Windows7 system, javascript1.8.5 version, DELL G3 computer

How does javascript convert a date to a timestamp?

Convert date to timestamp in js

The js string conversion timestamp can be converted to Date by using the built-in function Date (the time string to be converted), and then to the timestamp type, where the time string must be in the form of yyyy-MM-dd HH:mm:ss. Of course, it can be just yyyy-MM-dd, which is 2013-08-30, as follows:

You will get a Date type of data here. To get the timestamp data, you need to manipulate the date object. There are three ways to convert a date into a timestamp, as follows:

1. Var time1 = date.getTime ()

2.var time2 = date.valueOf ()

3.var time3 = Date.parse (date)

The first and second are accurate to milliseconds, and the third is only accurate to seconds. Milliseconds are replaced by 000. note: the acquired timestamp is divided by 1000 to get the Unix timestamp, which can be passed to the backend.

Extended data

Date () returns the date and time of the day.

GetDate () returns the day of the month (1-31) from the Date object.

GetDay () returns the day of the week (0-6) from the Date object.

GetMonth () returns the month (0-11) from the Date object.

GetFullYear () returns the year in four digits from the Date object.

Use the getFullYear () method instead of getYear ().

GetHours () returns the hours of the Date object (0-23).

GetMinutes () returns the minutes of the Date object (0-59).

GetSeconds () returns the number of seconds of the Date object (0-59).

GetMilliseconds () returns the milliseconds (0-999) of the Date object.

GetTime () returns the number of milliseconds since January 1, 1970.

GetTimezoneOffset () returns the minute difference between local time and Greenwich mean time (GMT).

GetUTCDate () returns the day of the month (1-31) from the Date object based on UTC.

GetUTCDay () returns the day of the week (0-6) from the Date object based on UTC.

GetUTCMonth () returns the month (0-11) from the Date object based on UTC.

GetUTCFullYear () returns a four-digit year from the Date object based on UTC.

GetUTCHours () returns the hours (0-23) of the Date object based on UTC.

GetUTCMinutes () returns the minutes (0-59) of the Date object based on UTC.

GetUTCSeconds () returns the seconds of the Date object based on UTC (0-59).

GetUTCMilliseconds () returns the milliseconds (0-999) of the Date object based on UTC.

Parse () returns the number of milliseconds from midnight on January 1, 1970 to the specified date (string).

SetDate () sets the day of the month in the Date object (1-31).

SetMonth () sets the month in the Date object (0-11).

SetFullYear () sets the year (four digits) in the Date object.

Use the setFullYear () method instead of setYear ().

SetHours () sets the hour (0-23) in the Date object.

SetMinutes () sets the minutes in the Date object (0-59).

SetSeconds () sets the seconds in the Date object (0-59).

SetMilliseconds () sets the milliseconds (0-999) in the Date object.

SetTime () sets the Date object in milliseconds.

SetUTCDate () sets the day of the month in the Date object (1-31) based on UTC.

SetUTCMonth () sets the month (0-11) in the Date object based on UTC.

SetUTCFullYear () sets the year (four digits) in the Date object based on UTC.

SetUTCHours () sets the hour (0-23) in the Date object based on UTC.

SetUTCMinutes () sets the minutes (0-59) in the Date object based on universal time.

SetUTCSeconds () sets the seconds in the Date object (0-59) based on UTC.

SetUTCMilliseconds () sets the milliseconds (0-999) in the Date object based on UTC.

ToSource () returns the source code for the object.

ToString () converts the Date object to a string.

ToTimeString () converts the time portion of the Date object to a string.

ToDateString () converts the date portion of the Date object to a string.

Use the toUTCString () method instead of toGMTString ().

ToUTCString () converts the Date object to a string based on universal time.

ToLocaleString () converts the Date object to a string based on the local time format.

ToLocaleTimeString () converts the time portion of the Date object to a string based on the local time format. ToLocaleDateString () converts the date portion of the Date object to a string based on the local time format.

UTC () returns the number of milliseconds from January 1, 1997 to the specified date, based on UTC. ValueOf () returns the original value of the Date object.

This is the end of the content of "what is the method of converting date to timestamp in javascript". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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