Surendar D Surendar D - 6 days ago 5
Android Question

How to parse date following format

How do parse this date format Thu Dec 01 00:00:00 GMT+05:30 2016 to normal date, month and year format.

ex:

String day = "Thu",

String month= "Dec",

String year= "2016"

Answer
String input = "Thu Dec 01 00:00:00 GMT+05:30 2016";
SimpleDateFormat parser = new SimpleDateFormat("EEE MMM d HH:mm:ss zzz yyyy");
Date date = parser.parse(input);

You can get the needed data from date. Or as you demand:

SimpleDateFormat dateFormat = new SimpleDateFormat("EEE");
String dayOfWeek = dateFormat.format(date);//Thu

dateFormat = new SimpleDateFormat("MMM");
String month = dateFormat.format(date);//Dec

dateFormat = new SimpleDateFormat("yyyy");
String year = dateFormat.format(date);//2016
Comments