Java Utililty Methods Time to String

List of utility methods to do Time to String

Description

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

Method

Stringtime2String(Date time)
time String
return timeFormat.format(time);
Stringtime2string(double t)
Converts double value of a time stamp to a string suitable for display.
NumberFormat form = NumberFormat.getInstance();
form.setMinimumIntegerDigits(2);
form.setMinimumFractionDigits(0);
form.setMaximumIntegerDigits(2);
form.setMaximumFractionDigits(2);
double stime = t;
int hours = (int) Math.floor(stime);
stime = (stime - hours) * 60;
...
Stringtime2String(long time)
time String
SimpleDateFormat df = new SimpleDateFormat("yy-MM-dd HH:mm");
Calendar toyear = Calendar.getInstance();
Calendar today = Calendar.getInstance();
toyear.set(Calendar.MONTH, Calendar.JANUARY);
toyear.set(Calendar.DATE, 1);
toyear.set(Calendar.HOUR_OF_DAY, 0);
toyear.set(Calendar.MINUTE, 0);
toyear.set(Calendar.SECOND, 0);
...
booleantimesAreEqual(Date date1, Date date2)
times Are Equal
if (date1 == null) {
    return date2 == null;
if (date2 == null) {
    return date1 == null;
return timeOnlyFormat.format(date1).equals(timeOnlyFormat.format(date2));
StringtimeStr(Date _Date)
time Str
if (_Date == null)
    return "";
SimpleDateFormat _SimpleDateFormat = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss", Locale.SIMPLIFIED_CHINESE);
return _SimpleDateFormat.format(_Date);
StringtimeString()
time String
return timestampToString(System.currentTimeMillis());
StringtimeString(double time)
time String
if (Double.isNaN(time)) {
    return "NA";
SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
formatter.setTimeZone(TimeZone.getTimeZone("GMT"));
long longTime = Math.round(time);
Date date = new Date(longTime);
return formatter.format(date);
...
StringtimeString(long tickNo, long offset)
time String
return timeFormat.format(time(tickNo, offset));
DatetimeString2Date(String time)
time String Date
if (time == null) {
    return null;
return new SimpleDateFormat(timeFormat).parse(time);
StringtimeToDeparture(String startTime)
Calculates minutes from now to a specific time in the future
int diffMinutes = -1;
Calendar now = Calendar.getInstance();
now.setTime(new Date());
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
Date date = null;
try {
    date = dateFormat.parse(startTime);
} catch (ParseException e) {
...