Home  >  Article  >  Web Front-end  >  How to convert jquery timestamp to date

How to convert jquery timestamp to date

WBOY
WBOYOriginal
2022-01-14 11:53:296768browse

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()".

How to convert jquery timestamp to date

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?&#39;0&#39;+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+&#39;-&#39;+add0(m)+&#39;-&#39;+add0(d)+&#39; &#39;+add0(h)+&#39;:&#39;+add0(mm)+&#39;:&#39;+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!

Statement:
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