How to convert date into timestamp in javascript
Javascript method to convert date into timestamp: 1. Use Date function to convert time string into Date type; 2. Convert Date type into timestamp type through "date.getTime()" and other methods That’s it.
The operating environment of this article: Windows 7 system, javascript version 1.8.5, DELL G3 computer
How to convert date to timestamp with javascript ?
Convert date to timestamp in js
#js string conversion timestamp can be converted first using the built-in function Date (the time string to be converted) It is a Date type, and then the Date type is converted into a timestamp type. The time string has requirements, and the format must be in the form of yyyy-MM-dd HH:mm:ss. Of course, it can also be just yyyy-MM-dd, that is 2013-08-30, as follows:
Here you will get a Date type data, to get the timestamp data, you need to operate the date object and convert the date into time There are three ways to stamp, as follows:
1. var time1 = date.getTime();
2.var time2 = date.valueOf();
3.var time3 = Date.parse(date);
First and second: yes Accurate to milliseconds. The third type: can only be accurate to seconds. Milliseconds are replaced by 000. Note: The obtained timestamp is divided by 1000 to obtain the Unix timestamp, which can be obtained by passing the value to the background.
Extended information
Date() returns the date and time of the current 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 as a four-digit number from a Date object.
getYear() Please use getFullYear() method instead.
getHours() returns the hours (0 ~ 23) of the Date object.
getMinutes() returns the minutes (0 ~ 59) of the Date object.
getSeconds() returns the 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 universal time.
getUTCDay() Returns the day of the week (0 ~ 6) from the Date object based on universal time.
getUTCMonth() Returns the month (0 ~ 11) from the Date object according to universal time.
getUTCFulYear() Returns the four-digit year from a Date object based on universal time.
getUTCHours() Returns the hour (0 ~ 23) of the Date object according to universal time.
getUTCMinutes() Returns the minutes (0 ~ 59) of the Date object according to universal time.
getUTCSeconds() returns the seconds (0 ~ 59) of the Date object according to universal time.
getUTCMilliseconds() returns the milliseconds (0 ~ 999) of the Date object according to universal time.
parse() Returns the number of milliseconds from midnight on January 1, 1970 to the specified date (string).
setDate() sets the day of the month (1 ~ 31) in the Date object.
setMonth() sets the month (0 ~ 11) in the Date object.
setFullYear() Sets the year (four digits) in the Date object.
setYear() Please use the setFullYear() method instead.
setHours() Sets the hours (0 ~ 23) in the Date object.
setMinutes() Sets the minutes (0 ~ 59) in the Date object.
setSeconds() Sets the seconds (0 ~ 59) in the Date object.
setMilliseconds() Sets the milliseconds (0 ~ 999) in the Date object.
setTime() Sets the Date object in milliseconds.
setUTCDate() Sets the day of the month (1 ~ 31) in the Date object according to universal time.
setUTCMonth() Sets the month (0 ~ 11) in the Date object according to universal time.
setUTCFulYear() Sets the year (four digits) in the Date object according to universal time.
setUTCHours() Sets the hour (0 ~ 23) in the Date object according to universal time.
setUTCMinutes() Sets the minutes (0 ~ 59) in the Date object according to universal time.
setUTCSeconds() Sets the seconds (0 ~ 59) in the Date object according to universal time.
setUTCMilliseconds() Sets the milliseconds (0 ~ 999) in the Date object according to universal time.
toSource() Returns the source code of the object.
toString() Converts Date object to string.
toTimeString() Converts the time part of the Date object to a string.
toDateString() Converts the date part of the Date object to a string.
toGMTString() Please use toUTCString() method instead.
toUTCString() Converts a Date object to a string according to universal time.
toLocaleString() Converts the Date object to a string according to the local time format.
toLocaleTimeString() Converts the time part of the Date object into a string according to the local time format. toLocaleDateString() Converts the date part of the Date object to a string according to the local time format.
UTC() Returns the number of milliseconds from January 1, 1997 to the specified date according to universal time. valueOf() returns the original value of the Date object.
Recommended learning: "javascript video tutorial"
The above is the detailed content of How to convert date into timestamp in javascript. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



How to use WebSocket and JavaScript to implement an online speech recognition system Introduction: With the continuous development of technology, speech recognition technology has become an important part of the field of artificial intelligence. The online speech recognition system based on WebSocket and JavaScript has the characteristics of low latency, real-time and cross-platform, and has become a widely used solution. This article will introduce how to use WebSocket and JavaScript to implement an online speech recognition system.

Golang time conversion: How to convert timestamp to string In Golang, time operation is one of the very common operations. Sometimes we need to convert the timestamp into a string for easy display or storage. This article will introduce how to use Golang to convert timestamps to strings and provide specific code examples. 1. Conversion of timestamps and strings In Golang, timestamps are usually expressed in the form of integer numbers, which represent the number of seconds from January 1, 1970 to the current time. The string is

WebSocket and JavaScript: Key technologies for realizing real-time monitoring systems Introduction: With the rapid development of Internet technology, real-time monitoring systems have been widely used in various fields. One of the key technologies to achieve real-time monitoring is the combination of WebSocket and JavaScript. This article will introduce the application of WebSocket and JavaScript in real-time monitoring systems, give code examples, and explain their implementation principles in detail. 1. WebSocket technology

In Go, you can use regular expressions to match timestamps: compile a regular expression string, such as the one used to match ISO8601 timestamps: ^\d{4}-\d{2}-\d{2}T \d{2}:\d{2}:\d{2}(\.\d+)?(Z|[+-][0-9]{2}:[0-9]{2})$ . Use the regexp.MatchString function to check if a string matches a regular expression.

JavaScript and WebSocket: Building an efficient real-time weather forecast system Introduction: Today, the accuracy of weather forecasts is of great significance to daily life and decision-making. As technology develops, we can provide more accurate and reliable weather forecasts by obtaining weather data in real time. In this article, we will learn how to use JavaScript and WebSocket technology to build an efficient real-time weather forecast system. This article will demonstrate the implementation process through specific code examples. We

JavaScript tutorial: How to get HTTP status code, specific code examples are required. Preface: In web development, data interaction with the server is often involved. When communicating with the server, we often need to obtain the returned HTTP status code to determine whether the operation is successful, and perform corresponding processing based on different status codes. This article will teach you how to use JavaScript to obtain HTTP status codes and provide some practical code examples. Using XMLHttpRequest

Golang Programming Tool: Best Practices for Timestamp Obtaining Introduction: In software development, timestamp is a very common concept. It is a numeric value that identifies the occurrence of a specific event, usually representing the number of milliseconds or nanoseconds since some reference point in time. In Golang, processing timestamps is very simple and efficient. This article will introduce the best practices for obtaining timestamps in Golang and provide specific code examples. Text: Get the current timestamp In Golang, getting the current timestamp is very simple. we can

Timestamp in PHP is an integer form representing time, usually the number of seconds that have passed since the first year of Unix (January 1, 1970 00:00:00 GMT). In programming, we often need to convert timestamps into other forms of integers. Here we will introduce how to convert PHP timestamps into integers, as well as specific code examples. In PHP, we can use the strtotime() function to convert the time string to a timestamp and then use date
