Set TimeZone in Flutter

565 views
Skip to first unread message

Hemanth Savarala

unread,
Oct 18, 2019, 1:09:22 AM10/18/19
to Flutter Development (flutter-dev)

I used to convert UTC time to TimeZone time like this in Android Java now in flutter how can I achieve.

public static String getTimeFullDateStr(Date date, String timeZone) {
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("h:mma, MMM dd, yyyy", Locale.US);
    TimeZone tz = null;
    if (timeZone.equalsIgnoreCase("")) {
        tz = TimeZone.getTimeZone("US/Pacific");
    } else {
        tz = TimeZone.getTimeZone(timeZone);
    }
    simpleDateFormat.setTimeZone(tz);
    String formattedDate = simpleDateFormat.format(date);
    formattedDate = formattedDate.replace("AM", "am").replace("PM", "pm");
    return formattedDate;
}

This is what i'm doing now in Flutter but don't know how to pass the timezone

DateFormat("h:mma, MMM dd" )
        .format(DateTime.parse(timeCreated))
        .replaceAll("AM", "am")
        .replaceAll("PM", "pm")
Reply all
Reply to author
Forward
0 new messages