Storage of time when node and MySQL mate

Source: Internet
Author: User

In MySQL I usually use the int type to store the time. The int type is only 11 bits.

But in JS we can usually use

var nowdate=date.now ();

To get the current time. JS is 13 bits. The last three digits represent the number of milliseconds. We can do simple processing to record the current time (accurate to the second) in case the time requirement is not very strict.

// gets the current time stamp function () {    return parseint (Date.now ()/+);}
/** * Formatted date * @param {[type]} date [description] * @param {[type]} pattern [description] * @return {[Type]} [Description]*/Date.format=function(date, pattern) {if(!date) {Date=NewDate; } Else {        if(!isDate (date)) {Date=Newdate (date); }} pattern= Pattern | | ' Yyyy-mm-dd '; vary =date.getfullyear (). toString (); varn \{m:date.getmonth ()+ 1,//MonthD:date.getdate (),// DayH:date.gethours (),//HourM:date.getminutes (),//minuteS:date.getseconds ()//Second    }; Pattern= Pattern.replace (/(y+)/ig,function(A, b) {returnY.substr (4-math.min (4, b.length));    });  for(varIincho) {pattern= Pattern.replace (NewRegExp (' (' + i + ' + ') ', ' G '),function(A, b) {return(O[i] < && b.length > 1)? ' 0 ' +O[i]: o[i];    }); }    returnpattern;}
/* * * Get date and time * @param  {[Type]} date [description] * @return {[type]}      */function  (date)    { // return Php.date ("y-m-d h:m:s", date);    return Date.format (date *, "Yyyy-mm-dd hh:mm:ss");}

This allows you to store time in a simple type such as int.

Storage of time when node and MySQL mate

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.