-2

I am new to Android so I was wondering how do i get Timezones with Gmt in recycler view in android?

Pooja SWS
  • 1
  • 2
  • This question is not related to recyler view in any ways ask question properly like "How to get Timezone in GMT in android" as string or extra. Next time be more specific here is a link to get time zone https://stackoverflow.com/questions/15068113/how-to-get-the-timezone-offset-in-gmtlike-gmt700-from-android-device/28695098 – krishank Tripathi Feb 24 '18 at 11:57
  • 3
    Possible duplicate of [How to get the timezone offset in GMT(Like GMT+7:00) from android device?](https://stackoverflow.com/questions/15068113/how-to-get-the-timezone-offset-in-gmtlike-gmt700-from-android-device) – Nike Kov Feb 24 '18 at 12:42

1 Answers1

0

1) Get defualt timezone using this code. This will give you the local time zone

Calendar c = Calendar.getInstance(TimeZone.getDefault());

2) TO get UTC or GMT use this below code

TimeZone.getTimeZone("GMT")

if your recycler view has a textview and you want to show time using GMT time zone. So you need to convert date or time in string format.

public static String getDateInFormatForDashboard(String apiDateStr) {
    SimpleDateFormat sdfFrom = new SimpleDateFormat("yyyy-MM-dd", Locale.US);
    sdfFrom.setTimeZone(TimeZone.getTimeZone("GMT"));        
    Date date = null;
    try {
        date = sdfFrom.parse(apiDateStr);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    SimpleDateFormat sdfTo = new SimpleDateFormat("d MMM", Locale.US);
    return sdfTo.format(date);
}
Shaon
  • 2,496
  • 26
  • 27