當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript moment.moment函數代碼示例

本文整理匯總了TypeScript中moment/moment.moment函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript moment函數的具體用法?TypeScript moment怎麽用?TypeScript moment使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了moment函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: transform

  transform(timeEnd: string, timeStart: string): string {
    if(!timeEnd || !timeStart) {
        return 'unknown';
    }

    let start = moment(timeStart);
    let end = moment(timeEnd);

    let diff = end.diff(start, 'minutes');
    if (diff < 1) {
        return '< 1 minute';
    } else if (diff == 1) {
        return '1 minute';
    } else if (diff < 60) {
        return `${diff} minutes`;
    }
    diff = end.diff(start, 'hours');
    if (diff === 1) {
        return '1 hour';
    } else if (diff < 24) {
        return `${diff} hours`;
    }
    diff = end.diff(start, 'days');
    if (diff === 1) {
        return '1 day';
    }
    return `${diff} days`;
  }
開發者ID:tmolteno,項目名稱:TART,代碼行數:28,代碼來源:time-elapsed-pipe.ts

示例2: onModeChanged

 onModeChanged(newMode: Number) {
   this.calendarMode = newMode;
   switch (this.calendarMode) {
     case 1:
       this.currentDate = this.currentDate.clone().startOf('month');
       break;
     case 2:
       this.currentDate = this.currentDate.clone().startOf('week');
       break;
     case 3:
       let firstMonthDiff = moment().diff(this.currentDate.startOf('week'), 'months');
       let secondMonthDiff = moment().diff(this.currentDate.endOf('week'), 'months');
       if (firstMonthDiff !== secondMonthDiff) {
         if (firstMonthDiff < secondMonthDiff && firstMonthDiff >= 0) {
           this.currentDate = moment().add(firstMonthDiff, 'months');
         } else {
           this.currentDate = moment().add(secondMonthDiff, 'months');
         }
       } else {
         this.currentDate = this.currentDate.clone().startOf('month');
       }
       break;
     default:
       this.currentDate = this.currentDate.clone().startOf('month');
       break;
   }
 }
開發者ID:waffle-iron,項目名稱:teki,代碼行數:27,代碼來源:schedular.ts

示例3: constructor

 constructor(req: IRequestState) {
     this.id = req.id;
     this.state = ViewRequestStates[req.status];
     this.pickUpTime = moment(req.pickUpTime);
     this.lineId = req.lineId;
     this.acceptingBus = req.acceptingBus;
 }
開發者ID:mzeen,項目名稱:SS2016-group2,代碼行數:7,代碼來源:ViewRequestState.ts

示例4: transform

 public transform(timestampMicros: number): any {
   if (!timestampMicros) {
     return '';
   }
   moment.locale(I18n.language);
   return moment(timestampMicros).format('LLL');
 }
開發者ID:mdharamadas1,項目名稱:admiral,代碼行數:7,代碼來源:locale-date.pipe.ts

示例5: transform

  transform(value: any): any {
    if (isNaN(value)) {
      return '';
    }

    return moment(new Date(value)).fromNow();
  }
開發者ID:iraghumitra,項目名稱:incubator-metron,代碼行數:7,代碼來源:time-lapse.pipe.ts

示例6: it

    it('end date is invalid if it is in the future', () => {

      expect(component.filterForm.get('endTime').valid).toBe(true);

      component.filterForm.patchValue({
        endTime: moment(new Date()).add(2, 'days').format(DEFAULT_TIMESTAMP_FORMAT)
      });

      expect(component.filterForm.get('endTime').valid).toBe(false);
    });
開發者ID:JonZeolla,項目名稱:incubator-metron,代碼行數:10,代碼來源:pcap-filters.component.spec.ts

示例7: isPublishedDate

export function isPublishedDate(start, end, format="YYYY-MM-DD")
{
    let info = {result: false, publishedStart: "", publishedEnd: "", code: 0};
    let s = void 0 === start ? null : moment(start);
    let e = void 0 === end || !moment(end).isValid() ? null : moment(end);
    
    //バリデーションチェック
    if (null === s || !s.isValid()) { info.code = 1; return info;}
    info.publishedStart = s.format(format);
    if (null === e)
    {
        info.publishedEnd = null;
    }
    else
    {
        if (!e.isValid()) { info.code = 1; return info; }
        if (s.isAfter(e)) { info.code = 2; return info; }
        info.publishedEnd = e.format(format);
    }
    info.result = true;
    return info;
}
開發者ID:gozaru9,項目名稱:new-river-fatman,代碼行數:22,代碼來源:common.ts

示例8: parseDate

 parseDate(inputString: string): Date {
     return moment(inputString, "DD.MM.YYYY HH:mm").toDate();
 }
開發者ID:dominikmathmann,項目名稱:ngTime,代碼行數:3,代碼來源:date.directive_1.ts

示例9: formatDate

 formatDate(inputDate: Date): string {
     return moment(inputDate).format("DD.MM.YYYY HH:mm")
     
   }
開發者ID:dominikmathmann,項目名稱:ngTime,代碼行數:4,代碼來源:date.directive_1.ts

示例10: saveConference

    saveConference(currentConference: Conference): Observable<Conference> {

        currentConference.startDate = Moment(currentConference.startDateStr).utc().toDate();
        currentConference.endDate = Moment(currentConference.endDateStr).utc().toDate();

        return this.onSaveConference(currentConference);
    }
開發者ID:rightincode,項目名稱:speakerregister,代碼行數:7,代碼來源:conference.service.ts


注:本文中的moment/moment.moment函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。