Java Date to String dateToString(java.util.Date currdate, String strFormat)

Here you can find the source of dateToString(java.util.Date currdate, String strFormat)

Description

date To String

License

Open Source License

Declaration

public static final String dateToString(java.util.Date currdate, String strFormat) 

Method Source Code


//package com.java2s;

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    private static String defaultDatePattern = "yyyy-MM-dd";

    public static final String dateToString(java.util.Date currdate, String strFormat) {
        String returnDate = "";
        try {/* w  w  w. j  ava  2  s.c  o m*/
            SimpleDateFormat sdf = new SimpleDateFormat(strFormat);
            if (currdate == null)
                return returnDate;
            else
                returnDate = sdf.format(currdate);
        } catch (NullPointerException e) {
        }
        return returnDate;
    }

    public static String format(Date date) {
        return date == null ? "" : format(date, getDatePattern());
    }

    public static String format(Date date, String pattern) {
        return date == null ? "" : new SimpleDateFormat(pattern).format(date);
    }

    public static String getDatePattern() {
        return defaultDatePattern;
    }
}

Related

  1. dateToString(Date pDate, String pFormat)
  2. dateToString(Date pdttValue, String pstrDateFormat)
  3. DateToString(Date thisdate, Locale locale)
  4. dateToString(final Date date)
  5. dateToString(final Date value, final boolean utc)
  6. dateToString(String date, String format)
  7. dateToString(String str, DateTimeFormatter dateTimeFormatter)
  8. dateToString1(Date date, String formatIn)
  9. dateToString_yyyyMMddHHmmssSSS(Date date)