Java : IsoEra with Examples
IsoEra (Java SE 21 & JDK 21) with Examples.
You will find code examples on most IsoEra methods.
Summary
final var locale = Locale.getDefault();
System.out.println(locale.toLanguageTag()); // en-US
{
final var era = IsoEra.CE;
System.out.println(era.getValue()); // 1
final var name = era.getDisplayName(TextStyle.FULL, locale);
System.out.println(name); // Anno Domini
}
{
final var era = IsoEra.BCE;
System.out.println(era.getValue()); // 0
final var name = era.getDisplayName(TextStyle.FULL, locale);
System.out.println(name); // Before Christ
}
final var date1 = LocalDate.of(2100, 12, 31);
System.out.println(date1); // 2100-12-31
System.out.println(date1.getEra()); // CE
final var date2 = LocalDate.of(-99, 1, 2);
System.out.println(date2); // -0099-01-02
System.out.println(date2.getEra()); // BCE
Enum Constants
BCE
final var era = IsoEra.BCE;
System.out.println(era.name()); // BCE
System.out.println(era.getValue()); // 0
CE
final var era = IsoEra.CE;
System.out.println(era.name()); // CE
System.out.println(era.getValue()); // 1
Methods
int getValue ()
final var era = IsoEra.CE;
System.out.println(era); // CE
System.out.println(era.getValue()); // 1
final var era = IsoEra.BCE;
System.out.println(era); // BCE
System.out.println(era.getValue()); // 0
static IsoEra of (int isoEra)
final var era1 = IsoEra.of(0);
System.out.println(era1); // BCE
final var era2 = IsoEra.of(1);
System.out.println(era2); // CE
static IsoEra valueOf (String name)
final var era1 = IsoEra.valueOf("BCE");
System.out.println(era1); // BCE
final var era2 = IsoEra.valueOf("CE");
System.out.println(era2); // CE
static IsoEra[] values ()
for (final var era : IsoEra.values()) {
System.out.println(era);
}
// Result
// ↓
//BCE
//CE
Methods declared in Enum
clone, compareTo, describeConstable, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
Please see the link below.
Methods declared in Era
adjustInto, get, getDisplayName, getLong, isSupported, query, range
Please see the link below.
Related posts
- Get the current time
- Basics of Date and Time
- Don't use the legacy Date and Calendar classes, use new APIs instead
- API Examples
- Calendar
- ChronoLocalDate
- ChronoLocalDateTime
- ChronoZonedDateTime
- Clock
- Date
- DateTimeException
- DateTimeParseException
- DayOfWeek
- Duration
- Era
- Instant
- InstantSource
- JapaneseDate
- LocalDate
- LocalDateTime
- LocalTime
- Month
- MonthDay
- OffsetDateTime
- OffsetTime
- Period
- Temporal
- TemporalAccessor
- TemporalAdjuster
- TemporalAdjusters
- TimeZone
- Year
- YearMonth
- ZonedDateTime
- ZoneId
- ZoneOffset