Java Utililty Methods Date to Time

List of utility methods to do Date to Time

Description

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

Method

StringgetTimeString(java.util.Date date)
get Time String
if (date == null)
    return "";
SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
String NDate = formatter.format(date);
return NDate;
StringgetTimeText(Date date)
get Time Text
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
int hour = calendar.get(Calendar.HOUR_OF_DAY);
String hourText = String.valueOf(hour);
if (hour < 10) {
    hourText = '0' + hourText;
int minutes = calendar.get(Calendar.MINUTE);
...
StringgetXSDDateTime()
get XSD Date Time
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
return simpleDateFormat.format(new Date());
StringgetXsdDateTime(Date time)
get Xsd Date Time
Date now = time;
DateFormat ISO8601Local = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
TimeZone timeZone = TimeZone.getDefault();
ISO8601Local.setTimeZone(timeZone);
int offset = timeZone.getOffset(now.getTime());
String sign = "+";
if (offset < 0) {
    offset = -offset;
...
StringgetXsdDateTime(final Date d)
get Xsd Date Time
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
if (d != null) {
    return sdf.format(d);
} else {
    return sdf.format(new Date());
DateremoveTime(Date date)
remove Time
try {
    return removeTimeDateFormat.parse(removeTimeDateFormat.format(date));
} catch (ParseException e) {
    e.printStackTrace();
    throw new RuntimeException(e);
StringserializeDateTime(final Date date)
Serialise a date as xsd:dateTime format with seconds to three decimal places (non-canonical)
final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'.'SSS'Z'");
format.setTimeZone(TimeZone.getTimeZone("UTC"));
return format.format(date);
StringserializeXsdDateTime(Date date)
serialize Xsd Date Time
return serializeXsdDateTime(date, TimeZone.getDefault());
StringstrTime(Date dt)
str Time
DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
return df.format(dt);
Stringto24HrTimeString(Date date)
Return the formatted string of the given date instance based on the 24 hour format specified for time in the System property.
if (date == null)
    return null;
String timeformat = null;
timeformat = time24HrFormat;
return format(date, timeformat);