字符串转换为日期的机器人 [英] convert String to Date in android

查看:146
本文介绍了字符串转换为日期的机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁知道如何将下面的字符串转换为日期?

anyone know how to convert the following string to Date?

周五7月30日16点19分36秒GMT + 02.00 2021

"Fri Jul 30 16:19:36 GMT+02.00 2021"

我想:

 SimpleDateFormat formatter = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzzz yyyy");
try {String temp = value2[i].trim();
     expiry = formatter.parse(temp);

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

不过,这是行不通的。

but,it doesn't work.

推荐答案

以Z 预计,格式为: GMT + 02:00 不是 GMT + 02.00 替换,它应该工作。

z expects the format GMT+02:00 not GMT+02.00 replace the . and it should work.

为我工作有以下code:

Worked for me with the following code:

    SimpleDateFormat formatter = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzzz yyyy");
    try {
        String temp = "Fri Jul 30 16:19:36 GMT+02:00 2021";
        Date expiry = formatter.parse(temp);
    } catch (Exception e) {
        e.printStackTrace();
    }

这篇关于字符串转换为日期的机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆