Java Utililty Methods Date Format As

List of utility methods to do Date Format As

Description

The list of methods to do Date Format As are organized into topic(s).

Method

StringgetDateAsRFC822String(Date date)
RFC822 has strict rules how to format a date.
return RFC822DATEFORMAT.format(date);
StringgetDateYYYYMMDD()
get Date YYYYMMDD
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
String NDate = formatter.format(new Date());
return NDate;
DategetDateYYYYMMDD(Object yyyymmdd)
Helper parsing two kinds of dates:
1.
if (yyyymmdd == null)
    return null;
String sdate = yyyymmdd.toString();
if (sdate.lastIndexOf('-') > sdate.indexOf('-')) {
    SimpleDateFormat formatter = s_formatsYMD[0];
    synchronized (formatter) { 
        return formatter.parse(sdate);
Calendar calendar = Calendar.getInstance();
SimpleDateFormat formatter = s_formatsYMD[1];
synchronized (formatter) { 
    calendar.setTime(formatter.parse(sdate));
int lastDay = calendar.getActualMaximum(Calendar.DATE);
calendar.set(Calendar.DATE, lastDay);
calendar.set(Calendar.HOUR_OF_DAY, 23);
calendar.set(Calendar.MINUTE, 59);
calendar.set(Calendar.SECOND, 59);
return calendar.getTime();
String[]getDateYYYYMMDD_HHSSMMNNN()
get Date YYYYMMDHHSSMMNNN
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd HHmmssms");
return sdf.format(new Date()).split("\\s+");
StringgetDateYyyyMmWithoutDash()
get Date Yyyy Mm Without Dash
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMM");
return simpleDateFormat.format(new Date());