Methods for processing timestamp as date format in JavaScript _javascript tips

Source: Internet
Author: User
Tags getdate
Public processing timestamp function
Copy Code code as follows:

/**
* Process timestamp converted to date format
* @param {Object} obj timestamp {10-bit timestamp needs to be multiplied by 1000; 13-bit timestamp does not need}
* @return {TypeName} return date format 2013-09-16
*/
function Fullnum (obj) {
if (number (obj) < 10) {
Return ' 0 ' + obj;
}else{
return obj;
}
}

1. The time stamp stored in PHP is 10 bits, and when JavaScript is processed it needs to be multiplied by 1000 to get the date format.
Copy Code code as follows:

var mystime = newdate (msg.pager.result[i].adsdate * 1000);
var addstime = mystime.getfullyear () + '-' + fullnum (number (Mystime.getmonth ()) + 1) + '-' + fullnum (mystime.getdate ());
Addstime Show Time is 2013-09-16.

2. The time stamp stored in Java is 13 bits, then the date format can be obtained in JavaScript processing without any processing required
Copy Code code as follows:

var mystime = newdate (msg.pager.result[i].adsdate);
var addstime = mystime.getfullyear () + '-' + fullnum (number (Mystime.getmonth ()) + 1) + '-' + fullnum (mystime.getdate ());
Direct use of addstime can be 2013-09-16
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.