collapseCorpse
collapseCorpse

Reputation: 57

Can not parse time into correct GMT

From API i get time as string "13:00:00Z" in this format and it is GMT 0 time zone.

I want to adjust it to my time zone which is GMT +4.

Upvotes: 0

Views: 70

Answers (1)

Devesh Kumawat
Devesh Kumawat

Reputation: 218

First you convert time into utc then after convert utc time to your local time zone. like example:

SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.getDefault());
                    simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
                    try {
                        Date utcDate = simpleDateFormat.parse("Your date");
                        SimpleDateFormat yourDateFormat = new SimpleDateFormat("dd MMM yyyy · HH'h'mm", Locale.getDefault());
                        String dateString = simpleDateFormat.format(utcDate);
                        binding.orderdate.setText(dateString);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
    

Upvotes: 1

Related Questions