JS time format

Source: Internet
Author: User
Tags dateformat diff

1 when a given time of 1997-10-10 is converted to a millisecond value, you need to extract such a parameter before using the GetTime

2 when a given value is a millisecond value converted to a date display

  function Formatbegintime (time) {    var year = Time.getfullyear ();    var mouth = Time.getmonth ();//smaller than the actual, if add 1 below the new time will not correspond to    var day = Time.getdate ();    var temp = new Date (year,mouth,day,00,00,00);    return temp;  }

3 format time, when less than one day hours and minutes, greater than the display of the date

functionConvertTime (TEM) {varCurdate =NewDate (); varNumeng = [' One ', ' I ', ' three ', ' four ', ' five ', ' six ', ' seven ', ' eight ', ' nine ', ' Ten ', ' eleven ', ' twelve ', ' Thirteen ', ' Fourteen ', ' fifteen ', ' sixteen ', ' Seventeen ', ' eighteen ', ' nineteen ', ' Twenty ', ' Twenty-one ', ' twenty-two ', ' Twenty-three ', ' twenty-four ', ' twenty-five ', ' twenty-six ', ' twenty-seven ', ' twenty-eight ', ' twenty-nine ', ' Thirty ', ' Thirty-one ', ' thirty-two ', ' thirty-three ', ' thirty-four ', ' thirty-five ', ' thirty-six ', ' thirty-seven ', ' thirty-eight ' , ' Thirty-nine ', ' Forty ', ' Forty-one ', ' forty-two ', ' forty-three ', ' forty-four ', ' Forty-five ', ' forty-six ', ' Forty-seven ', ' forty-eight ', ' forty-nine ', ' Fifty ', ' Fifty-one ', ' fifty-two ', ' fifty-three ', ' fifty-four ', ' fifty-five ' ', ' fifty-six ', ' fifty-seven ', ' fifty-eight ', ' fifty-nine ', ' Sixty ']; vardiff = curdate.gettime ()-tem; if(diff<3600000){        varminute = Math.ceil (diff/60000); minute = Numeng[minute-1]; TEM= Minute+ ' &nbsp;minutes ago '; }Else if(diff<86400000){        varhour = Math.ceil (diff/3600000); hour = Numeng[hour-1] TEM= hour+ ' &nbsp;hours ago '; }Else{        varDate =DateFormat (TEM); TEM=date; }    returntem;}functionDateFormat (time) {varTime =NewDate (time); varYear =time.getfullyear (); varmonth = Time.getmonth () +1; varDay =time.getdate (); functionZerofill (t) {if(t<10){            return' 0 ' +T; }Else{            returnT; }    }    returnyear+ "-" +zerofill (month) + "-" +Zerofill (day);}

JS time format

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.