Java Utililty Methods Long Number to Time

List of utility methods to do Long Number to Time

Description

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

Method

StringelapsedTimeToString(long elapsedTime)
elapsed Time To String
Date date = new Date(elapsedTime);
DateFormat formatter = new SimpleDateFormat("HH:mm:ss");
formatter.setTimeZone(TimeZone.getTimeZone("GMT"));
return formatter.format(date);
StringformattaData(long date)
formatta Data
try {
    return _data.format(new Date(date));
} catch (Exception e) {
return "";
StringformatTime(long date)
format Time
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss SSSS");
System.out.println(formatter.format(date));
return formatter.format(date);
StringformatTime(long ms)
format Time
Date d = new Date(ms);
Calendar c = new GregorianCalendar();
c.setTime(d);
String hours = String.valueOf(c.get(Calendar.HOUR));
String minutes = String.format("%02d", c.get(Calendar.MINUTE));
String seconds = String.format("%02d", c.get(Calendar.SECOND));
String millis = String.valueOf(c.get(Calendar.MILLISECOND));
String retval = hours + ":" + minutes + ":" + seconds + "." + millis
...
StringformatTimestampLong(long timestamp, String datepattern, TimeZone tz)
format a timestamp into a given date pattern string
long newTimestamp = timestamp;
DateFormat formatter = getDateFormat(datepattern, Locale.US, tz);
newTimestamp = newTimestamp / 1000;
newTimestamp = newTimestamp * 1000;
Date date = new Date(newTimestamp);
return formatter.format(date);
StringformatToUTC(long datetime)
format To UTC
return formatLongTime(datetime, "yyyyMMdd'T'HHmmss'Z'");
StringformatXSDateTime(long lastModified)
format XS Date Time
Date date = new Date(lastModified);
return formatXSDateTime(date);
StringgetAmPm(long time)
get Am Pm
SimpleDateFormat sf = new SimpleDateFormat("aa");
return sf.format(new Date(time));
longgetCollectTimeInLong(Date date)
Get the time in long format : "yyyyMMddHHmmss".
SimpleDateFormat collectTimeFormat = new SimpleDateFormat("yyyyMMddHHmmss");
return Long.valueOf(collectTimeFormat.format(date));
longgetDelay(long delay, long interval)
get Delay
long current = System.currentTimeMillis();
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
try {
    current = System.currentTimeMillis() - sf.parse(sf.format(new Date())).getTime();
} catch (ParseException e) {
if (current >= delay) {
    return current - delay;
...