目次
前提
intlパッケージが必要
dependencies:
intl: ^0.18.0 # 最新版を指定
ロケールの設定
import 'package:intl/date_symbol_data_local.dart';
void main() async {
// ロケールデータを初期化
await initializeDateFormatting('ja', null);
ロケールを設定しないとこんなのでる↓
例外が発生しました
LocaleDataException (LocaleDataException: Locale data has not been initialized, call initializeDateFormatting(<locale>).)
「土」を表示
print(DateFormat.E('ja').format(DateTime.now()))
// 土
「土曜日」を表示
print(DateFormat.EEEE('ja').format(DateTime.now()))
// 土曜日
他のフォーマとと組み合わせる
他のフォーマットDateFormat("yyyy-MM-dd");
こういうのと
組み合わせるのはできなさそうなので、文字列として組み合わせないといけない
final df = DateFormat("yyyy-MM-dd");
final e = DateFormat.E('ja');
print('${df.format(date)}(${e.format(date)})');
// 2025-01-03(月)