转换伦敦时间&格林尼治标准时间+6时间和时间日期

时间:2018-01-29 04:02:05

标签: java android timezone timezone-offset datetime-conversion

我已从谷歌收集伦敦时间。我想获得GMT + 6时间和日期。我尝试了很多方法,但我无法到达目的地。任何人都可以帮我解决这个问题。我已将所有字符串转换为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));

2 个答案:

答案 0 :(得分:0)

关注@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

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

您需要使用相同的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)));

<强>输出

2018-01-29 01:05:00(Gmt-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

答案 1 :(得分:0)

你可以在格林威治标准时间增加6小时。

  1. 获取伦敦时间并将其转换为 GMT
  2. 现在根据需要增加6小时 GMT +6
  3. Calender calender = Calender.getInstance(); calender.setTime("Enter GMT Time Here); calender.add(Calender.Hour, 6); System.out.println("Date/Time Here " +calender.getTime());