Android Date to String Convert getDateByFormatedString(String date)

Here you can find the source of getDateByFormatedString(String date)

Description

get Date By Formated String

License

Apache License

Declaration

public static String getDateByFormatedString(String date) 

Method Source Code

//License from project: Apache License 

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
import android.util.Log;

public class Main{
    private static final String TAG = "DateUtil";
    private static SimpleDateFormat formatter = new SimpleDateFormat(
            "yyyy-MM-dd HH:mm:ss");
    public static String getDateByFormatedString(String date) {
        Date mDate = null;/*from   w w w. j  a  va2s.  c o  m*/
        String dateFormated = "";
        Calendar cal = Calendar.getInstance();
        if (date != null && !date.isEmpty()) {
            try {
                mDate = DateTimeUtil.stringToDate(date);
            } catch (ParseException e) {
                Log.e(TAG, "Unparsable date");
            }
        }
        if (mDate != null) {
            cal.setTime(mDate);
            SimpleDateFormat dayFormat = new SimpleDateFormat("EEEE",
                    Locale.US);
            SimpleDateFormat month_date = new SimpleDateFormat("MMMM");
            int dayOfMonth = cal.get(Calendar.DAY_OF_MONTH);
            dateFormated += dayFormat.format(cal.getTime());
            dateFormated += ", ";
            dateFormated += month_date.format(cal.getTime());
            dateFormated += " " + String.valueOf(dayOfMonth);
        } else {

        }
        return dateFormated;
    }
    public static Date stringToDate(String date) throws ParseException {
        formatter.setTimeZone(TimeZone.getTimeZone("gmt"));
        return (formatter.parse(date));
    }
}

Related

  1. formatDate(String format, Date date)
  2. formatDate(final Date date)
  3. getCurrentDateStr()
  4. getCurrentDateStrs()
  5. getCurrentTimeStr()
  6. getDateTimeString(Date date)
  7. getDateTimeString(Date date, int format, Locale currentLocale)
  8. getFileName()
  9. getFormatString(Date date, String dateFormat)