1

I receive string from a server that contains date in this format (2014-06-04 10:26:06).

I want to convert it to date and apply this date format to it

SimpleDateFormat longDateFormat = new SimpleDateFormat("dd MMMM yyyy");

This is what i have at the moment, but its not working.

            String formattedDate = longDateFormat.format(messageGSON.getCreated());
            viewHolder.textViewMessageDate.setText(formattedDate);

I cant seem to find a solution, i think im missing a a step there

jmj
  • 237,923
  • 42
  • 401
  • 438
Nabdreas
  • 3,327
  • 4
  • 27
  • 30
  • possible duplicate of [Parsing date with Joda with time zone](http://stackoverflow.com/questions/4624992/parsing-date-with-joda-with-time-zone) – Basil Bourque Jun 26 '14 at 17:32

2 Answers2

3

Try this..

1) parse() String to Date

2) format() that Date to String

String formattedDate = longDateFormat.format(new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse(messageGSON.getCreated()));
viewHolder.textViewMessageDate.setText(formattedDate);
Hariharan
  • 24,741
  • 6
  • 50
  • 54
1

First you need to parse() String to Date, and then format() Date to String

jmj
  • 237,923
  • 42
  • 401
  • 438