Android Date String Parse convertDateTimeStrFormat(String dateStr, String pattern, String newPattern)

Here you can find the source of convertDateTimeStrFormat(String dateStr, String pattern, String newPattern)

Description

convert Date Time Str Format

Declaration

public static String convertDateTimeStrFormat(String dateStr,
            String pattern, String newPattern) throws ParseException 

Method Source Code

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

public class Main{
    public static String DEFAULTFORMAT = "yyyy-MM-dd HH:mm:ss";
    public static String convertDateTimeStrFormat(String dateStr,
            String pattern, String newPattern) throws ParseException {
        return DateTimeUtil.formatCalendar(
                DateTimeUtil.parseString(dateStr, pattern), newPattern);
    }//from   ww w  . j a  va 2 s  .  c om
    public static String formatCalendar(Calendar calendar) {
        return formatCalendar(calendar, DEFAULTFORMAT);
    }
    public static String formatCalendar(Calendar calendar, String pattern) {
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        // sdf.setTimeZone(TimeZone.getTimeZone(timeZone));
        return sdf.format(calendar.getTime());
    }
    public static Calendar parseString(String dateStr, String pattern)
            throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        Date date = sdf.parse(dateStr);
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        return calendar;
    }
    public static Calendar parseString(String dateStr)
            throws ParseException {
        return parseString(dateStr, DEFAULTFORMAT);
    }
}

Related

  1. GetDate(String time)
  2. dateTimeToDateObj(String date, String time)
  3. fromSlDateTime(final String dateString, final String timeString)
  4. convertTimeStumpToDate(String time)
  5. convertimeStumpToDate2(String time)
  6. convertStringToDate(String strDate, String pattern)
  7. parse(String pattern, String date)
  8. parse3339(String time)
  9. parseDate(String date)