将伦敦时间和日期转换为 GMT +6 时间和日期

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

我从Google收集了伦敦时间。我想获得 GMT+6 时间和日期。我尝试了很多方法,但我无法到达目的地。谁能帮我解决这个问题。我已将所有 string 转换为 int 。

这是我的代码:

   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));

关注@Affe 回答

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");

已更新

(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

如果你想要任何时区而不是遵循这个

您需要使用相同的日期格式解析日期

 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)));

输出

2018-01-29 01:05:00(格林威治标准时间 6)

亚洲时区(印度)

 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)));

输出

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

您可以将 GMT 时间增加 6 小时。

  1. 获取伦敦时间并将其转换为GMT
  2. 现在根据需要在该时间基础上增加 6 小时 GMT +6 .

Calender calender = Calender.getInstance(); calender.setTime("Enter GMT Time Here); calender.add(Calender.Hour, 6); System.out.println("Date/Time Here " +calender.getTime());