2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【Flutter】timezoneパッケージで日本時間取得

Posted at

概要

「flutter_local_notification」パッケージ使用時に「timezone」パッケージを使用する必要があり、その際に日本時間の取得に躓いた為、取得方法をまとめた。

flutter_local_notification

timezone

現在時刻の取得方法

パッケージのインポート

import 'package:timezone/data/latest_all.dart' as tz;
import 'package:timezone/timezone.dart' as tz;

初期化

// タイムゾーンデータベースの初期化
tz.initializeTimeZones();
// ローカルロケーションのタイムゾーンを東京に設定
tz.setLocalLocation(tz.getLocation("Asia/Tokyo")); 

現在時刻の取得

var now = tz.TZDateTime.now(tz.local)
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?