Convert a date format to Java

0

I have a method to parse from an xml in the form of a string, to a Request object. But in the xml the date comes to me like this:

2009-06-12T00: 00: 00 + 02: 00

Then I do not know what format to give the SimpleDateFormat to be able to convert that to Date. That would go inside the parenthesis in:

SimpleDateFormat formatter = new SimpleDateFormat("");

When I execute the method I get the following error:

Unparseable date: "2009-06-12T00:00:00+02:00"

I write the method below:

public Date convertirFecha(String s) throws ParseException{
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        Date fecha = formatter.parse(s);

        return fecha;
    }
    
asked by Angel Gonzalez Pena 21.09.2018 в 10:13
source

1 answer

3

It depends on the format you want to give the date, if you want to show only day month year, or how to show it

link
Here are the types of format you can put and that's what you have to put between the quotes

SimpleDateFormat formatter = new SimpleDateFormat("h:mm a");   

Result 12:08 PM

SimpleDateFormat formatter = new SimpleDateFormat("EEE, MMM d, ''yy");

Result Wed, Jul 4, '01

    
answered by 21.09.2018 / 10:49
source