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

StringgetTimeText(Long oldTime)
get Time Text
Date old = parseDate(oldTime, TimeFormat);
return formatTime(old);
StringgetUploadPath(String fileName, long time)
get Upload Path
SimpleDateFormat formater = new SimpleDateFormat("yyyy/MM/dd");
String uploadPath = "/upload/" + formater.format(new Date()) + "/" + time + getFileExt(fileName);
File dir = new File(getWebRoot() + uploadPath);
if (!dir.exists()) {
    try {
        dir.mkdirs();
    } catch (Exception e) {
        e.printStackTrace();
...
voidlogDuration(Logger logger, Level level, long startTime, String message)
log Duration
final long duration = System.currentTimeMillis() - startTime;
logger.log(level, message + " [Duration = " + duration + "ms]");
Stringlong2Str(long time)
long Str
synchronized (date) {
    date.setTime(time);
    return sdf.format(date);
StringlongToPgnDate(long time)
[Date "2009.10.07"]
return PGN_HEADER_DATE_FORMAT.format(new Date(time));
StringlongToTimedDate(long time)
Convent a long value into a date containing a time-stamp
SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);
return sdf.format(Long.valueOf(time));
StringprettyDate(long time)
pretty Date
long diff = (System.currentTimeMillis() - time) / 1000;
double day_diff = Math.floor(diff / 86400);
if (day_diff == 0 && diff < 60)
    return "just now";
if (diff < 120)
    return "1 minute ago";
if (diff < 3600)
    return Math.floor(diff / 60) + " minutes ago";
...
voidprintDuration(String message, long startTime)
print Duration
String duration = formatDuration(stopDuration(startTime));
System.out.println(message + ": " + duration + " sec");
voidprintExecutionTime(long startTime, long endTime, String className, String methodName)
Prints the execution time of a current running method in seconds.
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Calendar cal = Calendar.getInstance();
long runningTime = (endTime - startTime) / 1000; 
System.err.println("INFO: " + dateFormat.format(cal.getTime()) + " " + className + " " + methodName
        + " run for " + (runningTime == 1 ? runningTime + " second." : runningTime + " seconds."));
longstr2Long(String time)
str Long
if (time == null || time.isEmpty()) {
    return System.currentTimeMillis();
synchronized (sdf) {
    try {
        date = sdf.parse(time);
    } catch (ParseException e) {
        return Date.parse(time);
...