Search code examples
javaandroidtimezonetimezone-offsetdatetime-conversion

Convert London Time & Date To GMT +6 Time & Date


I have collect the London time from Google . I want to get GMT+6 time and Date. I tried many ways but i can't reach to my destination . Can anyone please help me to solve this. I have converted all string to int .

Here is My Code :

   CurrentDate = Date[1]+"/"+Month+"/" + Date[3];
             //  String dateFormat = Date[0]
                String[] Timee = Date[4].split(":");
                int hour = Integer.parseInt(Timee[0]);

                Log.e("Timeee", hour + " -- " + Timee[1] + " --" + Timee[2]);
                int seconds = Integer.parseInt(Timee[2]);
                int minutes = Integer.parseInt(Timee[1]);
                CurrentTime = seconds + minutes + hour;

                int date = Integer.parseInt(Date[1]);
                int year = Integer.parseInt(Date[3]);

                CurrentTime2 = Date[3]+"-" + Month +"-"+"-" + Date[1] +" " + hour+":" +Timee[1]+":"+Timee[2];





                 Date date1 = null;
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                try {
                    date1 = sdf.parse(CurrentTime2);
                }catch (Exception e){

                }
                sdf.setTimeZone(TimeZone.getTimeZone("Asia/Kolkata"));
                //        System.out.println(sdf.format(date));
                Log.e("@@@Date: ",String.valueOf(sdf.format(date1)));
                 DateAndTime = String.valueOf(sdf.format(date1));

Solution

  • follow @Affe Answer

    Convert UTC to current locale time

    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
    Date myDate = simpleDateFormat.parse("your data string");
    

    Updated

    (GMT-6:00) America/Bahia_Banderas
    
    (GMT-6:00) America/Belize
    (GMT-6:00) America/Cancun
    (GMT-6:00) America/Chicago
    (GMT-6:00) America/Costa_Rica
    (GMT-6:00) America/El_Salvador
    (GMT-6:00) America/Guatemala
    (GMT-6:00) America/Indiana/Knox
    (GMT-6:00) America/Indiana/Tell_City
    (GMT-6:00) America/Knox_IN
    (GMT-6:00) America/Managua
    (GMT-6:00) America/Matamoros
    (GMT-6:00) America/Menominee
    (GMT-6:00) America/Merida
    (GMT-6:00) America/Mexico_City
    (GMT-6:00) America/Monterrey
    (GMT-6:00) America/North_Dakota/Beulah
    (GMT-6:00) America/North_Dakota/Center
    (GMT-6:00) America/North_Dakota/New_Salem
    (GMT-6:00) America/Rainy_River
    (GMT-6:00) America/Rankin_Inlet
    (GMT-6:00) America/Regina
    (GMT-6:00) America/Resolute
    (GMT-6:00) America/Swift_Current
    (GMT-6:00) America/Tegucigalpa
    (GMT-6:00) America/Winnipeg
    (GMT-6:00) CST
    (GMT-6:00) CST6CDT
    (GMT-6:00) Canada/Central
    (GMT-6:00) Canada/East-Saskatchewan
    (GMT-6:00) Canada/Saskatchewan
    (GMT-6:00) Chile/EasterIsland
    (GMT-6:00) Etc/GMT+6
    (GMT-6:00) Mexico/General
    (GMT-6:00) Pacific/Easter
    (GMT-6:00) Pacific/Galapagos
    (GMT-6:00) SystemV/CST6
    (GMT-6:00) SystemV/CST6CDT
    (GMT-6:00) US/Central
    (GMT-6:00) US/Indiana-Starke
    

    if you want any of time zone than follow this

    you need to parse the date with same Dateformat

     SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String dd = "2018-01-29 12:35:00";
    
    
    
    
        Date date = null;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            date = sdf.parse(dd);
        }catch (Exception e){
    
        }
        sdf.setTimeZone(TimeZone.getTimeZone("America/Belize"));
     //        System.out.println(sdf.format(date));
        Log.e("@@@Date: ",String.valueOf(sdf.format(date)));
    

    OUTPUT

    2018-01-29 01:05:00 (Gmt-6)

    For Asia time zone (INDIA)

     SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String dd = "2018-01-29 12:35:00";
    
    
    
    
        Date date = null;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            date = sdf.parse(dd);
        }catch (Exception e){
    
        }
        sdf.setTimeZone(TimeZone.getTimeZone("Asia/Kolkata"));
      //        System.out.println(sdf.format(date));
        Log.e("@@@Date: ",String.valueOf(sdf.format(date)));
    

    OUTPUT

    2018-01-29 12:35:00 GMT+05:30