Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert String to Date in android

anyone know how to convert the following string to Date?

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

i tried:

 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.

like image 402
catherine8473 Avatar asked Aug 20 '26 19:08

catherine8473


1 Answers

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

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();
    }
like image 124
MByD Avatar answered Aug 23 '26 09:08

MByD



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!