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

WBOY
WBOYOriginal
2016-05-16 17:05:431039browse

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