【问题标题】:Convert London Time & Date To GMT +6 Time & Date [duplicate]将伦敦时间和日期转换为 GMT +6 时间和日期 [重复]
【发布时间】:2018-07-07 17:34:24
【问题描述】:

我从 Google 收集了伦敦时间。我想获得 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));

【问题讨论】:

  • 什么是Date[]
  • 我从 google 获取日期。日期[1] 日期,日期[3] = 年。
  • 如果你想指定时区(例如GMT+6),为什么不尝试在GregorianCalendar对象上指定时区?
  • 你的意思是 UTC 到 GMT。
  • 是 UTC 到 GMT 。我尝试了时区,但它不起作用。你能帮帮我吗?

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


【解决方案1】:

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

【讨论】:

  • 我想要 GMT+6 时间。
  • 请查看更新......
  • 什么是 f.format?我已经使用了 [将 UTC 转换为当前区域时间代码]
  • SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  • f 是你的 SimepleDateFormat
【解决方案2】:

您可以通过将 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());

【讨论】:

  • ???????????????????????????????
  • @TahaHossain 立即查看,
  • 无法正常显示伦敦时间和日期。
  • 您已采集伦敦时间,即 GMT +00。
  • 伦敦时间加上 6 小时,您可以得到 6 小时后的伦敦时间。您的方法似乎给出了正确的时间,但方法不正确。
猜你喜欢
  • 2015-12-12
  • 1970-01-01
  • 1970-01-01
  • 2017-12-21
  • 2021-05-02
  • 2016-11-12
  • 1970-01-01
  • 2014-04-11
  • 1970-01-01
相关资源
最近更新 更多