パッケージ、リポジトリ、アプリカテゴリを検索

GitHub リポジトリsadespresso/moment_dart

moment_dart

Moment は、Dart の DateTime オブジェクトを人間が読みやすいテキストに変換します。さらに多くの利点があります

moment_dart のプロジェクト画像
スター
21
フォーク
4
最終プッシュ(UTC)
2026/05/03
プロジェクト状態
公開中

元の README

以下は英語原文のスナップショットです。最新版は GitHub をご覧ください。

moment_dart

pub package License: MIT All Contributors

Inspired by moment.js

References

📖 Read documentation
🆕 Migrate to 5.x.x

Usage

Creating instance

There are multiple ways to create an instance.

// From DateTime
final a = DateTime.now().toMoment();

final b = Moment(DateTime(...));

// This instance won't be affected by global localization!
final c = Moment(b, localization: MomentLocalizations.koKr());
Setting global localization

By default, the global localization is en_US.

Moment.setGlobalLocalization(MomentLocalizations.fr());
Relative Duration

Relative durations are rather inprecise. See precise duration for accuracy and flexibility.

Read about thresholds, and more on docs

final yesterday = Moment.now() - const Duration(days: 1);
yesterday.fromNow(); // a day ago

final add5sec = Moment.now().add(const Duration(seconds: 5));
add5sec.fromNow(dropPrefixOrSuffix: true); // a few seconds
Precise duration

You can create localized human-readable duration text with abbreviation, highly-customizable units.

See more on docs. (delimiter, custom units, abbreviation...)

On Duration objects:

Duration(days: 67, hours: 3, minutes: 2).toDurationString(
  localization: MomentLocalizations.de(),
  form: Abbreviation.semi,
); // in 2 Mo. 7 Tg.

For Moment:

final epoch = Moment.fromMillisecondsSinceEpoch(0);
final now = DateTime(2023, DateTime.july, 14).toMoment();

print(epoch.fromPrecise(now)); // 53 years 7 months ago
Calendar
final Moment now = Moment.now();

print(now.calendar()); // Today at 03:00 PM
Other helpful methods

moment_dart provides numerous convenience methods. Works on both Moment and DateTime.

See all available options in the docs

final now = DateTime.now(); // July 19 2023 03:12 PM (UTC+8)

// ISO week, ISO week year
now.week; // 48
now.weekYear; // 2023

now.isLeapYear; // false

// Date creates new `DateTime` with hours, minutes, etc.. omitted
now.date; // July 19 2023 00:00 AM

now.clone(); // July 19 2023 03:12 PM

now.nextTuesday(); // July 25 2023 03:12 PM

// and many more!

Contributing

Contributions of any kind are welcome! Please refer to CONTRIBUTE.md

Contributors

Батмэнд Ганбаатар
Батмэнд Ганбаатар

💻 🚧 🌍 📖
Ultrate
Ultrate

💻 🌍
Muhammadyusuf
Muhammadyusuf

🌍 💻
Paweł
Paweł

🌍 💻
Батмэнд Ганбаатар GitHub avatar
GitHub 作者

Батмэнд Ганбаатар ↗

A creature powered by iced coffee @flow-mn, @unread-games

@gege-mnUlaanbaatar, Mongolia公式サイト ↗
言語Dart

カテゴリー

このリポジトリが公開するパッケージ

使用している依存関係

依存関係一覧 2 件

プロジェクトに合うリポジトリを選ぶには?

用途で絞り込み、開発状況を比較し、採用前に元のリポジトリで要件を確認しましょう。

  1. 名前・作者・説明で検索し、技術トピックで絞り込みます。
  2. スター、フォーク、最近のプッシュを比較します。スターは関心の目安であり、品質の保証ではありません。
  3. 利用前に GitHub で README、ライセンス、Issues を確認します。

情報源と管理

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗