Android Date to GMT Date Convert localDateFromGMTDate(Date dateGMT)

Here you can find the source of localDateFromGMTDate(Date dateGMT)

Description

local Date From GMT Date

License

Open Source License

Declaration

public static Date localDateFromGMTDate(Date dateGMT) 

Method Source Code

//package com.java2s;

import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

public class Main {
    public static Date localDateFromGMTDate(Date dateGMT) {

        Calendar calendarMGT = Calendar.getInstance();
        calendarMGT.setTimeInMillis(dateGMT.getTime());
        Calendar calendarLocal = (Calendar) calendarMGT.clone();

        TimeZone z = TimeZone.getDefault();
        int offset = z.getRawOffset();
        int offsetHrs = offset / 1000 / 60 / 60;
        int offsetMins = offset / 1000 / 60 % 60;

        // if (isInDayLight()) {
        // Log.i("daylight", "in Daylight saving time");
        // offsetHrs++;
        // }//from w w w.ja v  a2 s.  co m
        calendarLocal.add(Calendar.HOUR_OF_DAY, (offsetHrs));
        calendarLocal.add(Calendar.MINUTE, (offsetMins));

        Date dateLocal = new Date();
        dateLocal.setTime(calendarLocal.getTimeInMillis());
        return dateLocal;
    }
}