Home > Web Front-end > JS Tutorial > Methods to process timestamps in date format in javascript_javascript skills

Methods to process timestamps in date format in javascript_javascript skills

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 17:05:43
Original
1067 people have browsed it

Public processing timestamp function

Copy code The code is as follows:

/**
* Process the timestamp into date format
* @param {Object} obj timestamp {10-digit timestamp needs to be multiplied by 1000; 13-digit timestamp does not need to}
* @return {TypeName } Return date format 2013-09-16
* /
function fullnum(obj){
if(Number(obj) < 10){
return '0' obj;
}else{
return obj;
}
}

1. The timestamp stored in PHP is 10 digits, but when processed by javascript, it needs to be multiplied by 1000 to get the time in date format
Copy code The code is as follows:

var mystime = newDate(msg.pager.result[i].adsdate * 1000 );
var addstime = mystime.getFullYear() '-' fullnum(Number(mystime.getMonth()) 1) '-' fullnum(mystime.getDate());
//The time displayed by addstime is 2013-09-16

2. The timestamp stored in java is 13 digits, so you can get the time in date format without any processing in javascript
Copy code The code is as follows:

var mystime = newDate(msg.pager.result[i].adsdate) ;
var addstime = mystime.getFullYear() '-' fullnum(Number(mystime.getMonth()) 1) '-' fullnum(mystime.getDate());
//You can get it directly by using addstime 2013-09-16
Related labels:
source:php.cn
Statement of this Website
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
Latest Issues
What are JavaScript hook functions?
From 1970-01-01 08:00:00
0
0
0
What is JavaScript garbage collection?
From 1970-01-01 08:00:00
0
0
0
c++ calls javascript
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template