-2

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"
sasikumar
  • 12,540
  • 3
  • 28
  • 48
Surendar D
  • 5,554
  • 4
  • 36
  • 38
  • what is `normal date, month and year format.`? have you tried using https://developer.android.com/reference/java/text/SimpleDateFormat.html ? – Vladyslav Matviienko Nov 28 '16 at 08:23
  • @ Vlad Matvienko, That I know dude. I am expecting answer not command. I had given example know what is normal date. – Surendar D Nov 28 '16 at 08:45
  • 1
    @VladMatvienko I wish users like you, gives commands that have no help to nobody, will end one day. As I always say, everybody understands different, somebody wants this ready because they are dealing with other things at that moment so you can just give answer if you know or leave it blank to let other people answer it, do not give negative comments because this is NOYB --> "None Of Your Business" and they are not constructive, just destructive. – Bahadir Tasdemir Nov 28 '16 at 09:06
  • @webmaster, sorry, but people, who think that they can have others doing their job for free have to suffer. – Vladyslav Matviienko Nov 28 '16 at 09:12
  • @webmaster, You are teaching me not to teach others. Sorry, but where is the logic? – Vladyslav Matviienko Nov 28 '16 at 09:17
  • Possible duplicate of [Parse date in android](http://stackoverflow.com/questions/7042961/parse-date-in-android) – Vladyslav Matviienko Nov 28 '16 at 09:21
  • @VladMatvienko you have anger inside you, let it free. This is a Q & A site, so deal with just Q & A please. – Bahadir Tasdemir Nov 28 '16 at 09:51

2 Answers2

1
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
Bahadir Tasdemir
  • 10,325
  • 4
  • 49
  • 61
0

Try this:

 String strDate = "";
 SimpleDateFormat parser = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
 Date date= parser.parse(dateFromDB);

 String dayOfTheWeek = (String) android.text.format.DateFormat.format("EEEE", date);
 String stringMonth = (String) android.text.format.DateFormat.format("MMM", date); 
 String intMonth = (String) android.text.format.DateFormat.format("MM", date); 
 String year = (String) android.text.format.DateFormat.format("yyyy", date); 
 String day = (String) android.text.format.DateFormat.format("dd", date); 

also check these links: Android date parsing (Extracting month and year )

Get Value Of Day Month form Date Object in Android?

How to get the day, year, hours, min Individually from date format "yyyy-MM-dd'T'HH:mm:ss.SSSZ"?

Community
  • 1
  • 1
Deepak Sachdeva
  • 950
  • 8
  • 16