Home > Article > Web Front-end > How to convert jquery timestamp to date
How to convert jquery timestamp to date: 1. Use the Date and getTime() methods to get the current timestamp, the syntax is "new Date().getTime()"; 2. Use the Date object method to return the date The format is enough, the syntax is "new Date().getDate()".
The operating environment of this tutorial: windows10 system, jquery3.2.1 version, Dell G3 computer.
How to convert jquery timestamp to date
What is Unix timestamp (Unix timestamp): Unix timestamp (Unix timestamp), or It is called Unix time (Unix time) or POSIX time (POSIX time), which is a time representation method and is defined as the total number of seconds from 00:00:00 on January 1, 1970, Greenwich Mean Time to the present. Unix timestamps are not only used in Unix systems and Unix-like systems, but are also widely used in many other operating systems.
Methods to obtain the current timestamp
var timestamp1 = Date.parse(new Date()); var timestamp2 = (new Date()).valueOf(); var timestamp3 = new Date().getTime();
The first method: the timestamp obtained is to change the milliseconds to 000 for display, the second and third methods are to obtain timestamp of the current millisecond.
Convert timestamp to ordinary date format
Date attribute method
function add0(m){return m<10?'0'+m:m } function format(shijianchuo) { //shijianchuo是整数,否则要parseInt转换 var time = new Date(shijianchuo); var y = time.getFullYear(); var m = time.getMonth()+1; var d = time.getDate(); var h = time.getHours(); var mm = time.getMinutes(); var s = time.getSeconds(); return y+'-'+add0(m)+'-'+add0(d)+' '+add0(h)+':'+add0(mm)+':'+add0(s); }
Recommended related video tutorials: jQuery video tutorial
The above is the detailed content of How to convert jquery timestamp to date. For more information, please follow other related articles on the PHP Chinese website!