Processing timestamp in javascript in date format _ javascript skills

Source: Internet
Author: User
This article describes how to process a timestamp as a date in javascript. The following is a good example. If you are interested, refer to the public processing timestamp function.

The Code is as follows:


/**
* Convert the processing timestamp to the date format
* @ Param {Object} obj timestamp {10-bit timestamp must be multiplied by 1000; 13-bit timestamp is not required}
* @ Return {TypeName} return date format
*/
Function fullnum (obj ){
If (Number (obj) <10 ){
Return '0' + obj;
} Else {
Return obj;
}
}


1. The timestamp stored in PHP is 10 bits. During javascript processing, you must multiply the timestamp by 1000 to get the date format time.

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 addstime display time is


2. If the timestamp stored in java is 13 BITs, you can obtain the date format time without any processing in javascript.

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 ());
// Use addstime directly to obtain

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.