https://github.com/tasxatzial/time-formatter
https://github.com/tasxatzial/time-formatter
time-formatting
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/tasxatzial/time-formatter
- Owner: tasxatzial
- License: mit
- Created: 2021-05-24T04:09:27.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-07-08T08:36:25.000Z (over 2 years ago)
- Last Synced: 2025-03-02T15:49:46.991Z (8 months ago)
- Topics: time-formatting
- Language: Java
- Homepage:
- Size: 12.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Time formatter
A simple class that can be used to return an approximation of the elapsed time in nanoseconds in a human-readable format.
It also converts time periods between nanoseconds, hours, minutes, seconds, milliseconds, and microseconds.
## Usage
```java
import timeutils.Time;
long startTime = System.nanoTime();
...
long endTime = System.nanoTime();
// Create a Time instance
System.out.println(new Time(endTime - startTime));
// Do not create a Time instance, use the static method instead
System.out.println(Time.toString(endTime - startTime));
```
## Examples
| Period | Format | Approx. Percent Error |
|----------------|----------|-------|
| 423 | 423ns | 0% |
| 423423 | 423μs | 0.1% |
| 3423423 | 3.4ms | 0.7% |
| 53423423 | 53ms | 0.8% |
| 7653623423L | 7.7s | 0.6% |
| 47653623423L | 48s | 0.7% |
| 447653623423L | 7min 28s | 0.1% |
| 5447653623423L | 1h 31min | 0.2% |