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


TypeScript DateTime.fromMillis方法代碼示例

本文整理匯總了TypeScript中luxon.DateTime.fromMillis方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript DateTime.fromMillis方法的具體用法?TypeScript DateTime.fromMillis怎麽用?TypeScript DateTime.fromMillis使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在luxon.DateTime的用法示例。


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

示例1: age

  protected async age(opts: CommandOptions) {
    let username;
    const parsed = opts.parameters.match(/([^@]\S*)/g);

    if (_.isNil(parsed)) {
      username = opts.sender.username;
    } else {
      username = parsed[0].toLowerCase();
    }

    const user = await global.users.getByName(username);
    if (_.isNil(user) || _.isNil(user.time) || _.isNil(user.time.created_at)) {
      sendMessage(prepare('age.failed', { username }), opts.sender);
    } else {
      const units: string[] = ['years', 'months', 'days', 'hours', 'minutes'];
      const diff = DateTime.fromMillis(new Date(user.time.created_at).getTime()).diffNow(['years', 'months', 'days', 'hours', 'minutes']);
      const output: string[] = [];
      for (const unit of units) {
        if (diff[unit]) {
          const v = -Number(diff[unit]).toFixed();
          output.push(v + ' ' + getLocalizedName(v, 'core.' + unit));
        }
      }
      if (output.length === 0) {
        output.push(0 + ' ' + getLocalizedName(0, 'core.minutes'));
      }
      sendMessage(prepare('age.success.' + (opts.sender.username === username.toLowerCase() ? 'withoutUsername' : 'withUsername'), {
          username,
          diff: output.join(', '),
        }), opts.sender);
    }
  }
開發者ID:sogehige,項目名稱:SogeBot,代碼行數:32,代碼來源:userinfo.ts

示例2: timestampToArray

 timestampToArray(ms: number): number[] {
   return luxonToArray(
     LuxonDateTime.fromMillis(ms, {
       zone: this.timeZoneName
     })
   )
 }
開發者ID:BorjaPintos,項目名稱:fullcalendar,代碼行數:7,代碼來源:main.ts

示例3: timestamp

export function timestamp(input: any) {
  if (!isInputValid(input)) {
    return '-';
  }
  const tz = SETTINGS.feature.displayTimestampsInUserLocalTime ? undefined : SETTINGS.defaultTimeZone;
  const thisMoment = DateTime.fromMillis(parseInt(input, 10), { zone: tz });
  return thisMoment.isValid ? thisMoment.toFormat('yyyy-MM-dd HH:mm:ss ZZZZ') : '-';
}
開發者ID:emjburns,項目名稱:deck,代碼行數:8,代碼來源:timeFormatters.ts

示例4: reminder

  private async reminder() {
    if (!this.cleanedUpOnStart) {
      this.cleanedUpOnStart = true;
      this.settings._.closingAt = 0;
    } else if (this.settings._.closingAt !== 0) {
      const when = DateTime.fromMillis(this.settings._.closingAt, { locale: global.general.settings.lang });
      const lastRemindAtDiffMs = -(DateTime.fromMillis(this.settings._.lastRemindAt).diffNow().toObject().milliseconds || 0);

      const minutesToGo = when.diffNow(['minutes']).toObject().minutes || 0;
      const secondsToGo = round5(when.diffNow(['seconds']).toObject().seconds || 0);

      if (minutesToGo > 1) {
        // countdown every minute
        if (lastRemindAtDiffMs >= constants.MINUTE) {
          sendMessage(
            prepare('systems.scrim.countdown', {
              type: this.settings._.type,
              time: minutesToGo.toFixed(),
              unit: getLocalizedName(minutesToGo.toFixed(), 'core.minutes'),
            }),
            { username: getOwner() },
          );
          this.settings._.lastRemindAt = Date.now();
        }
      } else if (secondsToGo <= 60 && secondsToGo > 0) {
        // countdown every 15s
        if (lastRemindAtDiffMs >= 15 * constants.SECOND) {
          sendMessage(
            prepare('systems.scrim.countdown', {
              type: this.settings._.type,
              time: String(secondsToGo === 60 ? 1 : secondsToGo),
              unit: secondsToGo === 60 ? getLocalizedName(1, 'core.minutes') : getLocalizedName(secondsToGo, 'core.seconds'),
            }),
            { username: getOwner() },
          );
          this.settings._.lastRemindAt = Date.now();
        }
      } else {
        this.settings._.closingAt = 0;
        this.countdown();
      }
    }
  }
開發者ID:sogehige,項目名稱:SogeBot,代碼行數:43,代碼來源:scrim.ts

示例5: relativeTime

export function relativeTime(input: any) {
  if (!isInputValid(input)) {
    return '-';
  }
  const now = Date.now();
  const inputNumber = parseInt(input, 10);
  const inFuture = inputNumber > now;
  const thisMoment = DateTime.fromMillis(inputNumber);
  const baseText = distanceInWordsToNow(thisMoment.toJSDate(), { includeSeconds: true });
  return thisMoment.isValid ? `${inFuture ? 'in ' : ''}${baseText}${inFuture ? '' : ' ago'}` : '-';
}
開發者ID:emjburns,項目名稱:deck,代碼行數:11,代碼來源:timeFormatters.ts

示例6: subage

  protected async subage(opts: CommandOptions) {
    let username;
    const parsed = opts.parameters.match(/([^@]\S*)/g);

    if (_.isNil(parsed)) {
      username = opts.sender.username;
    } else {
      username = parsed[0].toLowerCase();
    }

    const user = await global.users.getByName(username);
    const subCumulativeMonths = _.get(user, 'stats.subCumulativeMonths', undefined);
    const subStreak = _.get(user, 'stats.subStreak', undefined);
    const localePath = 'subage.' + (opts.sender.username === username.toLowerCase() ? 'successSameUsername' : 'success') + '.';

    if (_.isNil(user) || _.isNil(user.time) || _.isNil(user.time.subscribed_at) || _.isNil(user.is.subscriber) || !user.is.subscriber) {
      sendMessage(prepare(localePath + (subCumulativeMonths ? 'notNow' : 'never'), {
        username,
        subCumulativeMonths,
        subCumulativeMonthsName: getLocalizedName(subCumulativeMonths || 0, 'core.months'),
      }), opts.sender);
    } else {
      const units: string[] = ['years', 'months', 'days', 'hours', 'minutes'];
      const diff = DateTime.fromMillis(user.time.subscribed_at).diffNow(['years', 'months', 'days', 'hours', 'minutes']);
      const output: string[] = [];
      for (const unit of units) {
        if (diff[unit]) {
          const v = -Number(diff[unit]).toFixed();
          output.push(v + ' ' + getLocalizedName(v, 'core.' + unit));
        }
      }
      if (output.length === 0) {
        output.push(0 + ' ' + getLocalizedName(0, 'core.minutes'));
      }

      sendMessage(prepare(localePath + (subStreak ? 'timeWithSubStreak' : 'time'), {
        username,
        subCumulativeMonths,
        subCumulativeMonthsName: getLocalizedName(subCumulativeMonths || 0, 'core.months'),
        subStreak,
        subStreakName: getLocalizedName(subStreak || 0, 'core.months'),
        diff: output.join(', '),
      }), opts.sender);
    }
  }
開發者ID:sogehige,項目名稱:SogeBot,代碼行數:45,代碼來源:userinfo.ts

示例7: lastseen

  protected async lastseen(opts: CommandOptions) {
    try {
      const parsed = opts.parameters.match(/^([\S]+)$/);
      if (parsed === null) {
        throw new Error();
      }

      const user = await global.users.getByName(parsed[0]);
      if (_.isNil(user) || _.isNil(user.time) || _.isNil(user.time.message)) {
        sendMessage(global.translate('lastseen.success.never').replace(/\$username/g, parsed[0]), opts.sender);
      } else {
        const when = DateTime.fromMillis(user.time.message, { locale: global.general.settings.lang});
        sendMessage(global.translate('lastseen.success.time')
          .replace(/\$username/g, parsed[0])
          .replace(/\$when/g, when.toLocaleString(DateTime.DATETIME_MED_WITH_SECONDS)), opts.sender);
      }
    } catch (e) {
      sendMessage(global.translate('lastseen.failed.parse'), opts.sender);
    }
  }
開發者ID:sogehige,項目名稱:SogeBot,代碼行數:20,代碼來源:userinfo.ts

示例8: followage

  protected async followage(opts: CommandOptions) {
    let username;
    const parsed = opts.parameters.match(/([^@]\S*)/g);

    if (_.isNil(parsed)) {
      username = opts.sender.username;
    } else {
      username = parsed[0].toLowerCase();
    }

    const isFollowerUpdate = await global.api.isFollowerUpdate({
      id: opts.sender.userId,
    });
    debug('userinfo.followage', JSON.stringify(isFollowerUpdate));

    const user = await global.users.getByName(username);
    if (_.isNil(user) || _.isNil(user.time) || _.isNil(user.time.follow) || _.isNil(user.is.follower) || !user.is.follower) {
      sendMessage(prepare('followage.' + (opts.sender.username === username.toLowerCase() ? 'successSameUsername' : 'success') + '.never', { username }), opts.sender);
    } else {
      const units: string[] = ['years', 'months', 'days', 'hours', 'minutes'];
      const diff = DateTime.fromMillis(user.time.follow).diffNow(['years', 'months', 'days', 'hours', 'minutes']);
      const output: string[] = [];
      for (const unit of units) {
        if (diff[unit]) {
          const v = -Number(diff[unit]).toFixed();
          output.push(v + ' ' + getLocalizedName(v, 'core.' + unit));
        }
      }
      if (output.length === 0) {
        output.push(0 + ' ' + getLocalizedName(0, 'core.minutes'));
      }

      sendMessage(prepare('followage.' + (opts.sender.username === username.toLowerCase() ? 'successSameUsername' : 'success') + '.time', {
          username,
          diff: output.join(', '),
        }), opts.sender);
    }
  }
開發者ID:sogehige,項目名稱:SogeBot,代碼行數:38,代碼來源:userinfo.ts

示例9:

dt.set({ hour: 3 }).hour;

const f = { month: 'long', day: 'numeric' };
dt.setLocale('fr').toLocaleString(f);
dt.setLocale('en-GB').toLocaleString(f);
dt.setLocale('en-US').toLocaleString(f);

DateTime.fromObject({ zone: 'America/Los_Angeles' });
DateTime.local().setZone('America/Los_Angeles');

DateTime.utc(2017, 5, 15);
DateTime.utc();
DateTime.local().toUTC();
DateTime.utc().toLocal();

DateTime.fromMillis(1527780819458).toMillis();

/* Duration */
const dur = Duration.fromObject({ hours: 2, minutes: 7 });
dt.plus(dur);
dur.hours;
dur.minutes;
dur.seconds;

dur.as('seconds');
dur.toObject();
dur.toISO();

/* Interval */
const later = DateTime.local();
const i = Interval.fromDateTimes(now, later);
開發者ID:horiuchi,項目名稱:DefinitelyTyped,代碼行數:31,代碼來源:luxon-tests.ts


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