user1448108
user1448108

Reputation: 477

How to change string to datetime format in android?

I am working on android project. I am setting date and time but it is displaying in the following format.

Mon Nov 19 11:00:00 GMT+05:30 2012

In my database table the datetime column datatype is datetime. So how can I change the above output to datetime format to store it in database.

Any help in this regard will be thankful.

Upvotes: 0

Views: 127

Answers (1)

thepoosh
thepoosh

Reputation: 12587

you should probably read a bit about SimpleDateFormat, it's the way to parse String into Date.

the way to do this is to create a pattern for the formatter, then create the formatter and after that parse the Strings.

String pattern = "EEE, dd MMM yyyy HH:mm:ss z";
SimpleDateFormat format = new SimpleDateFormat(pattern);
Date myDate = format.parse(str);

Upvotes: 2

Related Questions