Skip to content

Instantly share code, notes, and snippets.

@onacit
Last active December 2, 2018 08:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save onacit/9f67e77d19cd60ee43a8dc936d3a9bd7 to your computer and use it in GitHub Desktop.
Save onacit/9f67e77d19cd60ee43a8dc936d3a9bd7 to your computer and use it in GitHub Desktop.
Prints information from java.time.temporal.ChronoUnit.
import java.time.temporal.*;
public class ChronoUnitMatrix {
public static void main(final String... args) {
System.out.printf("%-10s%-6s%-6s%s\n", "name", "time", "date",
"duration (estimated) (seconds)");
System.out.printf("%-10s%-6s%-6s%s\n", "---------", "-----", "-----",
"---------------------------------------------------------------");
for (final ChronoUnit value : ChronoUnit.values()) {
System.out.printf("%-10s%-6b%-6b%s (%b) (%d)\n", value.name(),
value.isTimeBased(), value.isDateBased(),
value.getDuration(), value.isDurationEstimated(),
value.getDuration().get(ChronoUnit.SECONDS));
}
}
}
@onacit
Copy link
Author

onacit commented Dec 2, 2018

java version "11" 2018-09-25
Java(TM) SE Runtime Environment 18.9 (build 11+28)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11+28, mixed mode)
name      time  date  duration (estimated) (seconds)
--------- ----- ----- ---------------------------------------------------------------
NANOS     true  false PT0.000000001S (false) (0)
MICROS    true  false PT0.000001S (false) (0)
MILLIS    true  false PT0.001S (false) (0)
SECONDS   true  false PT1S (false) (1)
MINUTES   true  false PT1M (false) (60)
HOURS     true  false PT1H (false) (3600)
HALF_DAYS true  false PT12H (false) (43200)
DAYS      false true  PT24H (true) (86400)
WEEKS     false true  PT168H (true) (604800)
MONTHS    false true  PT730H29M6S (true) (2629746)
YEARS     false true  PT8765H49M12S (true) (31556952)
DECADES   false true  PT87658H12M (true) (315569520)
CENTURIES false true  PT876582H (true) (3155695200)
MILLENNIA false true  PT8765820H (true) (31556952000)
ERAS      false true  PT8765820000000H (true) (31556952000000000)
FOREVER   false false PT2562047788015215H30M7.999999999S (true) (9223372036854775807)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment