• <tfoot id='KbUQQ'></tfoot>

    <i id='KbUQQ'><tr id='KbUQQ'><dt id='KbUQQ'><q id='KbUQQ'><span id='KbUQQ'><b id='KbUQQ'><form id='KbUQQ'><ins id='KbUQQ'></ins><ul id='KbUQQ'></ul><sub id='KbUQQ'></sub></form><legend id='KbUQQ'></legend><bdo id='KbUQQ'><pre id='KbUQQ'><center id='KbUQQ'></center></pre></bdo></b><th id='KbUQQ'></th></span></q></dt></tr></i><div id='KbUQQ'><tfoot id='KbUQQ'></tfoot><dl id='KbUQQ'><fieldset id='KbUQQ'></fieldset></dl></div>

    <legend id='KbUQQ'><style id='KbUQQ'><dir id='KbUQQ'><q id='KbUQQ'></q></dir></style></legend>
      <bdo id='KbUQQ'></bdo><ul id='KbUQQ'></ul>

      1. <small id='KbUQQ'></small><noframes id='KbUQQ'>

        Java 日期时间转换为给定时区

        时间:2023-09-25

        <small id='jgtlq'></small><noframes id='jgtlq'>

            1. <legend id='jgtlq'><style id='jgtlq'><dir id='jgtlq'><q id='jgtlq'></q></dir></style></legend>

                  <bdo id='jgtlq'></bdo><ul id='jgtlq'></ul>

                    <tbody id='jgtlq'></tbody>
                  <i id='jgtlq'><tr id='jgtlq'><dt id='jgtlq'><q id='jgtlq'><span id='jgtlq'><b id='jgtlq'><form id='jgtlq'><ins id='jgtlq'></ins><ul id='jgtlq'></ul><sub id='jgtlq'></sub></form><legend id='jgtlq'></legend><bdo id='jgtlq'><pre id='jgtlq'><center id='jgtlq'></center></pre></bdo></b><th id='jgtlq'></th></span></q></dt></tr></i><div id='jgtlq'><tfoot id='jgtlq'></tfoot><dl id='jgtlq'><fieldset id='jgtlq'></fieldset></dl></div>

                • <tfoot id='jgtlq'></tfoot>
                  本文介绍了Java 日期时间转换为给定时区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个格式为 Tue, 30 Apr 2019 16:00:00 +0800 的 DateTime,即 RFC 2822 格式日期

                  I have a DateTime in the format of Tue, 30 Apr 2019 16:00:00 +0800 which is RFC 2822 formatted date

                  我需要将其转换为 DateTime 中的给定时区,即 +0800

                  I need to convert this to the given timezone in the DateTime which is +0800

                  所以如果我总结一下,

                  DateGiven = Tue, 30 Apr 2019 16:00:00 +0800
                  DateWanted = 01-05-2019 00:00:00
                  

                  如何在 Java 中实现这一点?我已经尝试了下面的代码,但它比当前时间少 08 小时,即

                  How can i achieve this in Java? I have tried the below code but it gives 08 hours lesser than the current time which is

                  30-04-2019 08:00:00
                  

                  我试过的代码

                  String pattern = "EEE, dd MMM yyyy HH:mm:ss Z";
                  SimpleDateFormat format = new SimpleDateFormat(pattern);
                  Date startDate = format.parse(programmeDetails.get("startdate").toString());
                  
                  //Local time zone   
                   SimpleDateFormat dateFormatLocal = new SimpleDateFormat("yyyy-MMM-dd HH:mm:ss");
                  
                  //Time in GMT
                  Date dttt= dateFormatLocal.parse( dateFormatGmt.format(startDate) );
                  

                  推荐答案

                  在@ole v.v 的解释的帮助下,我将两个日期时间值分开1次2. 时区

                  with the help of @ole v.v's explanation i have separated the datetime value for two 1. time 2. timezone

                  然后我使用此编码来提取与给定时区相关的日期时间

                  then i used this coding to extract the datetime which is related to the given timezone

                  //convert datetime to give timezone 
                      private static String DateTimeConverter (String timeVal, String timeZone)
                      {
                          SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                  
                  
                      SimpleDateFormat offsetDateFormat2 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
                  
                          offsetDateFormat2.setTimeZone(TimeZone.getTimeZone(timeZone));
                          String result =null;
                          try {
                              result = offsetDateFormat2.format(format.parse(timeVal));
                          } catch (java.text.ParseException e) {
                              // TODO Auto-generated catch block
                              e.printStackTrace();
                          }
                  
                          return result;
                      }
                  

                  这篇关于Java 日期时间转换为给定时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Java - 查找正在使用的 tzdata 版本,无论 JRE 版本如何 下一篇:从 SimpleTimeZone 获取 ZoneId

                  相关文章

                  • <bdo id='WXQXl'></bdo><ul id='WXQXl'></ul>

                    <tfoot id='WXQXl'></tfoot>

                    <small id='WXQXl'></small><noframes id='WXQXl'>

                      <legend id='WXQXl'><style id='WXQXl'><dir id='WXQXl'><q id='WXQXl'></q></dir></style></legend>

                      <i id='WXQXl'><tr id='WXQXl'><dt id='WXQXl'><q id='WXQXl'><span id='WXQXl'><b id='WXQXl'><form id='WXQXl'><ins id='WXQXl'></ins><ul id='WXQXl'></ul><sub id='WXQXl'></sub></form><legend id='WXQXl'></legend><bdo id='WXQXl'><pre id='WXQXl'><center id='WXQXl'></center></pre></bdo></b><th id='WXQXl'></th></span></q></dt></tr></i><div id='WXQXl'><tfoot id='WXQXl'></tfoot><dl id='WXQXl'><fieldset id='WXQXl'></fieldset></dl></div>