Java Locale Format formatDate(String dateStr, String format, String toFormat)

Here you can find the source of formatDate(String dateStr, String format, String toFormat)

Description

format Date

License

Apache License

Declaration

public static String formatDate(String dateStr, String format,
            String toFormat) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.text.DateFormat;

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    public static String formatDate(String dateStr, String format,
            String toFormat) {/* w  ww .  j av  a2  s  . c  o  m*/
        return format(parseDate(dateStr, format), toFormat);
    }

    public static String formatDate(Date date) {
        return formatDateByFormat(date, "yyyy-MM-dd");
    }

    public static String format(Date date, String format) {
        String result = "";
        try {
            if (date != null) {
                DateFormat dateFormat = new SimpleDateFormat(format);
                result = dateFormat.format(date);
            }
        } catch (Exception localException) {
        }
        return result;
    }

    public static String format(Date date) {
        return format(date, "yyyy-MM-dd");
    }

    public static Date parseDate(String dateStr, String format) {
        Date date = null;
        try {
            SimpleDateFormat dateFormat = new SimpleDateFormat(format);

            date = dateFormat.parse(dateStr);
        } catch (Exception localException) {
        }
        return date;
    }

    public static Date parseDate(String dateStr) {
        return parseDate(dateStr, "yyyy-MM-dd");
    }

    public static String formatDateByFormat(Date date, String format) {
        String result = "";
        if (date != null) {
            try {
                SimpleDateFormat sdf = new SimpleDateFormat(format);
                result = sdf.format(date);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
        return result;
    }
}

Related

  1. formatDate(final Date date, final String pattren)
  2. formatDate(java.util.Date d, String format)
  3. formatDate(java.util.Date d, String format)
  4. formatDate(java.util.Date date, String formatPattern)
  5. formatDate(String _Date)
  6. formatDate(String pattern, Date date, String valueForNull)
  7. formatDate(String strDate, Locale locale)
  8. formatDate(String value, Locale locale)
  9. formatDate2Date(Date date, String format)