Convert Longs to Seconds and Milliseconds
From Java Example Source Code
Contents |
[edit] Overview - Convert Longs to Seconds and Milliseconds
This is a example of Java program.
[edit] Java Source Code
- Package: example.calendardate
- File: LongToMSec.java
package example.calendardate; /** * Convert longs (time_t in UNIX terminology) to seconds. */ public class LongToMSec { 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); } }
[edit] What Result You Can Get
Run the program, you will get:
1.0 1.1 1.024
[edit] Required External Libraries and/or Files for this Java Example
Need nothing.
[edit] How to Run this Java Example Program
We recommend running this Java example program with Eclipse.
For assistance in working with Eclipse, please see How to Run Java Program with Eclipse.
It's fairly easy.
[edit] Question & Answer
Any question?
Click edit and post your question or answer here.
