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

StringdateToTimeString(Date date)
return time value only of specified date in format: HH:mm:ss
return dateToStringWithPattern(date, "HH:mm:ss");
DatedateToUTCDate(Date d)
date To UTC Date
String strDate = "";
GregorianCalendar calendar = new GregorianCalendar();
calendar.setTime(d);
int utcOffsetInMinutes = -(calendar.get(Calendar.ZONE_OFFSET) + calendar.get(Calendar.DST_OFFSET))
        / (60 * 1000);
calendar.add(Calendar.MINUTE, utcOffsetInMinutes);
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
return calendar.getTime();
...
StringdateToUtcString(Date date)
Transform given Date into String using pattern yyyy-MM-dd'T'HH:mm:ss'Z'.
final SimpleDateFormat sdf = new SimpleDateFormat(DATE_AND_TIME_FORMATS[0]);
sdf.setTimeZone(TZ_UTC);
return sdf.format(date);
StringdateToW3c(Date d)
Convert a Date to a W3C String.
String ret = theW3cFormat.format(d);
return ret;
StringdateToW3CDTF(Date date)
date To WCDTF
SimpleDateFormat w3cdtf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
String s = w3cdtf.format(date);
int index = s.length() - 2;
return s.substring(0, index) + ":" + s.substring(index);
StringdateToW3CDTF(Date date)
Creates a String that represents the Date passed to it in W3C Date and Time Format.
String s = w3cdtf.get().format(date);
int index = s.length() - 2;
return s.substring(0, index) + ":" + s.substring(index);
StringdateToyyyyMMddHHmmss(Date date)
date Toyyyy M Mdd H Hmmss
java.text.DateFormat df = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return df.format(date);