This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import net.time4j.Duration; | |
import net.time4j.ClockUnit; | |
import java.text.ParseException; | |
import java.time.LocalTime; | |
import java.time.temporal.TemporalAmount; | |
public class DurationFormatPattern { | |
public static void main(String... args) throws ParseException { | |
String input = "5.2345"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PatternWith00Literals { | |
private static final Map<String, ChronoFormatter<PlainDate>> PARSERS; | |
static { | |
Map<String, ChronoFormatter<PlainDate>> parsers = new HashMap<>(); | |
parsers.put("ddMMyyyy", create("0000yyyy|00MMyyyy|dd00yyyy|ddMMyyyy")); | |
parsers.put("MMddyyyy", create("0000yyyy|MM00yyyy|00ddyyyy|MMddyyyy")); | |
parsers.put("yyyyMMdd", create("yyyy0000|yyyyMM00|yyyy00dd|yyyyMMdd")); | |
PARSERS = Collections.unmodifiableMap(parsers); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import net.time4j.PlainDate; | |
import net.time4j.calendar.*; | |
import net.time4j.format.expert.*; | |
import java.util.Locale; | |
import java.text.ParseException; | |
public class OldJapaneseDate { | |
public static void main(String... args) throws ParseException { | |
ChronoFormatter<JapaneseCalendar> jf = | |
ChronoFormatter.ofPattern("Gy年M月d日", PatternType.CLDR, Locale.JAPANESE, JapaneseCalendar.axis()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import net.time4j.*; | |
import net.time4j.format.expert.*; | |
public class UntilMidnight { | |
public static void main(String... args) throws ParseException { | |
PlainTime t = Iso8601Format.EXTENDED_WALL_TIME.parse("12:03:00"); | |
Duration<ClockUnit> duration = | |
Duration.inClockUnits().between(t, PlainTime.midnightAtEndOfDay()); // until 24:00 | |
Duration.Formatter<ClockUnit> f = Duration.formatter(ClockUnit.class, "hh:mm:ss"); | |
System.out.println(f.format(duration)); // 11:57:00 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import net.time4j.PlainTime; | |
import net.time4j.format.expert.Iso8601Format; | |
import java.text.ParseException; | |
import java.time.LocalTime; | |
import static net.time4j.PlainTime.*; | |
public class RoundingOfTime { | |
public static void main(String... args) throws ParseException { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// example shows how to set up a Time4J-formatter to parse calendar dates like "2017-01-18" or "2017/01/18" etc. | |
// and finally converts to old type java.util.Date (as bridge to legacy APIs) | |
// see also: http://time4j.net/javadoc-en/net/time4j/format/expert/ChronoFormatter.Builder.html#skipUnknown-java.util.function.IntPredicate-int- | |
import java.text.*; | |
import java.util.*; | |
import net.time4j.*; | |
import net.time4j.format.expert.*; | |
public class SkipDemo { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import net.time4j.*; | |
public class PreviousWakeupTime { | |
public static void main(String... args) { | |
// example in local time (ignoring timezone) | |
PlainTimestamp tsp = | |
PlainTimestamp.nowInSystemTime() | |
.with(PlainTime.COMPONENT.setToPrevious(PlainTime.of(7, 45))); | |
System.out.println(tsp); // 2016-11-07T07:45 (called on 2016-11-08T06:38) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import net.time4j.*; | |
import net.time4j.tz.ZonalOffset; | |
import net.time4j.format.expert.*; | |
import java.util.Locale; | |
public class PrintingMaxMoment { | |
public static void main(String... args) { | |
ChronoFormatter<Moment> cf = | |
ChronoFormatter.setUp(Moment.axis(), Locale.ROOT) | |
.addInteger(PlainDate.YEAR, 4, 9, SignPolicy.SHOW_WHEN_NEGATIVE) // suppress leading plus-sign |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.time.*; | |
import net.time4j.*; | |
import net.time4j.format.expert.*; | |
import java.util.Locale; | |
public class DoubleTimeAndZoneInfo { | |
private static final ChronoFormatter<Moment> FORMATTER = | |
ChronoFormatter.setUp(Moment.axis(), Locale.US) | |
.addPattern("HHmm z (", PatternType.CLDR) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Locale; | |
import net.time4j.PlainDate; | |
import net.time4j.format.expert.ChronoFormatter; | |
import net.time4j.format.expert.PatternType; | |
import net.time4j.tz.OffsetSign; | |
import net.time4j.tz.ZonalOffset; | |
/** |
NewerOlder