Java Utililty Methods Date to String

List of utility methods to do Date to String

Description

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

Method

StringDate2StringSec(Date date)
Date String Sec
SimpleDateFormat formatter = new SimpleDateFormat(DefaultLongFormat);
return formatter.format(date);
Stringdatetime(Date date)
datetime
return formatter.format(date);
StringdateTime2String(Date dateTime, DateFormat dateFormat)
date Time String
if (dateTime == null)
    return null;
return dateFormat.format(dateTime);
StringdateTimeISO(final java.util.Date date)
Returns the given date as an ISO date and time string ( "YYYY-MM-DD HH:MM:SS" )
if (date != null) {
    SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_TIME_ISO_FORMAT);
    return dateFormat.format(date);
} else {
    return "";
DatedateTimeToZero(Date date)
date Time To Zero
if (date == null) {
    return null;
return strToDtSimpleFormat(dateFormat(date));
StringdateTo14String(Date date)
date To String
if (date == null) {
    return null;
java.text.SimpleDateFormat dateFormat = new java.text.SimpleDateFormat("yyyyMMddHHmmss");
return dateFormat.format(date);
StringdateToBOMCStrDate(Date date)
date To BOMC Str Date
try {
    SimpleDateFormat simpledateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String s = simpledateformat.format(date);
    s = StrToBOMCStrDate(s);
    return s;
} catch (Exception e) {
    return "";
CalendardateToCalendar(Date fecha, String formato)
date To Calendar
try {
    if (nullToBlank(fecha).equals("")) {
        return null;
    SimpleDateFormat df = new SimpleDateFormat(formato);
    String text = df.format(fecha);
    return stringToCalendar(text, formato);
} catch (Exception e) {
...
StringdateToDateString(Date date, Locale locale)
convert a java date to a string of type "yyyy-mm-dd hh:mm:ss"
if (locale == null)
    locale = Locale.ITALIAN;
String t = DateFormat.getTimeInstance(DateFormat.MEDIUM, locale).format(date);
String[] tmptime = t.split("\\.");
String d = DateFormat.getDateInstance(DateFormat.SHORT, locale).format(date);
String[] tmpdate = d.split("/");
String hour = tmptime[0].trim();
if (hour.length() == 1) {
...
StringdateToDDMMYYYYStr(Date dateTime)
date To DDMMYYYY Str
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DATE_DDMMYYYY_FORMAT);
return simpleDateFormat.format(dateTime);