0

so I use intl package. here is my code

import 'package:intl/date_symbol_data_local.dart';
import 'package:intl/intl.dart';

String toString(DateTime originalDate) {
    initializeDateFormatting();
    final DateFormat formatter = DateFormat("EEEE, d MMMM. HH:mm zzz", "id");
    final String formatted = formatter.format(originalDate);
    return formatted;
  }

as you can see, I am trying to make DateTime as a string using "EEEE, d MMMM. HH:mm zzz" format. so I expect I will have the result date string like this:

Senin, 24 Mei. 18:00 WIB.

but I have error whenever I have that zzz in the format. if I remove the zzz then it should be fine.

I guess I need to put a TimeZone ID in my code above. because I has this unimplemented error in date_format_field.dart file

String formatTimeZone(DateTime date) {
    throw UnimplementedError();
  }

but I don't know how to set the timezoneID to my code. my TimeZone ID is "Asia/Jakarta"

I am okay if you have different code or not using intl package at all. as long as I can specify the timezone and the locale ID

Alexa289
  • 8,089
  • 10
  • 74
  • 178
  • [`package:intl` has not implemented time zone formatting](https://github.com/dart-lang/intl/issues/74) (nor parsing). You instead probably should use [`package:timezone`](https://pub.dev/packages/timezone) instead. – jamesdlin May 24 '21 at 05:13

1 Answers1

0

duplicate of Dart - How to format DateTime based on device timezone?

try using this:

String toString(DateTime originalDate) {
    initializeDateFormatting();
    final DateFormat formatter = DateFormat("EEEE, d MMMM. HH:mm zzz").parseUTC(dateTime).toLocal();
    final String formatted = formatter.format(originalDate);
    return formatted;
  }
flutter_bee
  • 150
  • 9