Created
August 11, 2020 02:00
-
-
Save ham-burger/2476b7ec3f5fed5c2cfa357f94837faf to your computer and use it in GitHub Desktop.
[Dart]datetimeをフォーマットする拡張関数
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:intl/intl.dart'; | |
extension DateTimeExtension on DateTime { | |
String toFormattedString({String format = 'yyyy/MM/dd HH:mm'}) { | |
var formatter = DateFormat(format, "ja_JP"); | |
var formatted = formatter.format(this); | |
return formatted; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:intl/date_symbol_data_local.dart'; | |
void main() async { | |
// DateFormatを事前に初期化する必要がある | |
await initializeDateFormatting("ja_JP", null); | |
// some functions | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment