Convert longs (time_t in UNIX terminology) to seconds
public class Main {
public static void main(String[] args) {
System.out.println(msToSecs(1000));
System.out.println(msToSecs(1100));
System.out.println(msToSecs(1024));
}
/** Convert a long ("time_t") to seconds and milliseconds */
public static String msToSecs(long t) {
// The first attempt fails for the case "1024"
//return t/1000 + "." + t%1000;
return Double.toString(t / 1000D);
}
}
Home
Java Book
Runnable examples
Java Book
Runnable examples
Date Convert:
- Convert Calendar to java.sql.Date
- Convert day of year to day of month
- Convert java.util.Date to java.sql.Time after calculation
- Convert java.util.Date to java.sql.Date after calculation
- Convert java.util.Date to java.sql.Date
- Convert Date into milliseconds
- Convert date to GMT
- Convert day of the year to date
- Convert milliseconds to readable string
- Elapsed time in hours/minutes/seconds
- Convert longs (time_t in UNIX terminology) to seconds