【问题标题】:How can i convert the date and time from Fri Sep 08 09:33:00 GMT+05:30 2017 to "08-09-2017 09:33"如何将日期和时间从 Fri Sep 08 09:33:00 GMT+05:30 2017 转换为“08-09-2017 09:33”
【发布时间】:2018-02-17 06:13:57
【问题描述】:

我尝试在 android 中将时间从 2017 年 9 月 8 日星期五 09:33:00 GMT+05:30 转换为“08-09-2017 09:33”,但我得到的输出如下 08-09-2017 04: 03 这里时间不正确..下面我写我的代码请解决谢谢。

String dateTime = "Fri Sep 08 09:33:00 GMT+05:30 2017"

DateFormat inputFormat = new SimpleDateFormat( "E MMM dd HH:mm:ss 'GMT'z yyyy", Locale.ENGLISH);

    Date dateone = null;

    try {
        dateone = inputFormat.parse(dateTime);

        DateFormat outputFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm",
                Locale.ENGLISH);
        outputFormat.setTimeZone(TimeZone.getTimeZone("UTC"));

        dateTimeForUpdate = outputFormat.format(dateone);


    } catch (ParseException e) {
        e.printStackTrace();
    }

【问题讨论】:

    标签: android


    【解决方案1】:

    您将时区设置为UTC04:03 是该时区的正确时间。如果您想在 (+05:30) 时区获取时间,请将其设置为 DateFormat 对象。

    【讨论】:

      【解决方案2】:

      试试这样:

          outputFormat.setTimeZone(TimeZone.getTimeZone("GMT+5:30"));
          dateTimeForUpdate = outputFormat.format(dateone);
          System.out.println(dateTimeForUpdate);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-09-04
        • 1970-01-01
        • 2017-01-26
        • 2023-03-05
        • 2019-11-06
        • 1970-01-01
        相关资源
        最近更新 更多