Use JS to complete the date format task of millisecond format data

Source: Internet
Author: User

Background data creationtime in the background is the date type

Milliseconds into the May-2 April day format.

  1. Get the month day get date Otime
  2. function Getmoth (str) {
  3. var odate = new Date (str),
  4. Omonth = Odate.getmonth () +1,
  5. Oday = Odate.getdate (),
  6. Otime = Getzf (omonth) +'-' + GETZF (oday);//Last splicing time
  7. return otime;
  8. };
  9. Console.log (Getmoth (1465959000));//How to use

Milliseconds converted to Month Day + time and minute format 1970-01-18 07:12:39

0 Operations: For example, 2012-2-2 will become 2012-02-02

Method of Use: Getmydate (data[i].creationtime);

  1. Obtained date Otime
  2. function Getmydate (str) {
  3. var odate = new Date (str),
  4. Oyear = Odate.getfullyear (),
  5. Omonth = Odate.getmonth () +1,
  6. Oday = Odate.getdate (),
  7. Ohour = Odate.gethours (),
  8. Omin = Odate.getminutes (),
  9. OSen = Odate.getseconds (),
  10. Otime = oyear +'-' + GETZF (omonth) + '-' + GETZF (oday) + ' + GETZF (ohour) +': ' + GETZF (omin) +': ' +getzf (OS EN);//Last splicing time
  11. return otime;
  12. };
  13. Complement 0 Operations
  14. function Getzf (num) {
  15. if (parseint (num) < ) {
  16. num = ' 0 ' +num;
  17. }
  18. return num;
  19. }

Milliseconds converted to month and day time and minute format

  1. /*
  2. JS by the number of milliseconds to get the date
  3. Use: (New Date (Data[i].creationtime)). Format ("Yyyy-mm-dd hh:mm:ss. S ")
  4. */
  5. Date.prototype.Format = function (FMT) {//author:meizz
  6. var o = {
  7. "m+": this.getmonth () + 1,//month
  8. "d+": this.getdate (),//day
  9. "H +": this.gethours (),//hour
  10. "m+": this.getminutes (),//min
  11. "s+": This.getseconds (),//Sec
  12. "q+": Math.floor ((This.getmonth () + 3)/ 3),//quarterly
  13. "S": this.getmilliseconds ()//MS
  14. };
  15. if (/(y+)/.test (FMT)) FMT = Fmt.replace (regexp.$1, (this.getfullyear () + ""). substr (4-regexp.$1.  length));
  16. For (var k in O)
  17. if (New RegExp ("(" + K + ")"). Test (FMT)) FMT = Fmt.replace (regexp.$1, (regexp.$1.length = = 1)?  (O[k]): (("xx" + o[k]). substr (("" + O[k]).));
  18. return FMT;
  19. };

Use JS to complete the date format task of millisecond format data

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.