Java Code Examples for org.threeten.bp.format.DateTimeFormatter#format()
The following examples show how to use
org.threeten.bp.format.DateTimeFormatter#format() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Examples.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Main method. * @param args no arguments needed */ public static void main(String[] args) { Clock clock = Clock.systemDefaultZone(); ZonedDateTime zdt = ZonedDateTime.now(clock); System.out.println("Current date-time: " + zdt); ZonedDateTime zdtNewYork = ZonedDateTime.now(Clock.system(ZoneId.of("America/New_York"))); System.out.println("Current date-time in New York: " + zdtNewYork); ZonedDateTime zdtParis = ZonedDateTime.now(Clock.system(ZoneId.of("Europe/Paris"))); System.out.println("Current date-time in Paris: " + zdtParis); LocalDateTime ldt = LocalDateTime.now(clock); System.out.println("Current local date-time: " + ldt); Year year = Year.now(clock); System.out.println("Year: " + year.getValue()); LocalDate today = LocalDate.now(clock); System.out.println("Today: " + today); System.out.println("Current day-of-year: " + today.get(DAY_OF_YEAR)); LocalTime time = LocalTime.now(clock); System.out.println("Current time of day: " + time); LocalDate later = LocalDate.now(clock).plusMonths(2).plusDays(3); System.out.println("Two months three days after today: " + later); // ISOPeriod period = ISOPeriod.of(3, MONTHS); // LocalDate moreLater = LocalDate.now(clock).plus(period); // System.out.println("Period " + period + " after today : " + moreLater); LocalDate dec = LocalDate.now(clock).with(DECEMBER); System.out.println("Change to same day in December: " + dec); LocalDate lastDayOfMonth = LocalDate.now(clock).with(lastDayOfMonth()); System.out.println("Last day of month: " + lastDayOfMonth); /// LocalDate tempDate = LocalDate.now(clock); // DateTimeFields fri13matcher = DateTimeFields.of( // DAY_OF_WEEK, FRIDAY.getValue(), DAY_OF_MONTH, 13); // boolean fri13 = fri13matcher.matches(tempDate); // System.out.println("Is Friday the Thirteenth: " + fri13); LocalDateTime dt = LocalDateTime.of(2008, 3, 30, 1, 30); System.out.println("Local date-time in Spring DST gap: " + dt); ZonedDateTime resolved = ZonedDateTime.of(dt, ZoneId.of("Europe/London")); System.out.println("...resolved to valid date-time in Europe/London: " + resolved); String formattedRFC = DateTimeFormatter.RFC_1123_DATE_TIME.format(resolved); System.out.println("...printed as RFC1123: " + formattedRFC); DateTimeFormatter f = new DateTimeFormatterBuilder() .appendValue(YEAR, 4, 10, SignStyle.ALWAYS) .appendLiteral(' ') .appendText(MONTH_OF_YEAR) .appendLiteral('(') .appendValue(MONTH_OF_YEAR) .appendLiteral(')') .appendLiteral(' ') .appendValue(DAY_OF_MONTH, 2) .toFormatter(Locale.ENGLISH); String formatted = f.format(resolved); System.out.println("...printed using complex format: " + formatted); MonthDay bday = MonthDay.of(DECEMBER, 3); System.out.println("Brazillian birthday (no year): " + bday); }
Example 2
Source File: DateTime.java From yql-plus with Apache License 2.0 | 2 votes |
/** * Formats the given datetime object according to the provided pattern. * * @see <a href="http://download.java.net/jdk8/docs/api/java/time/format/DateTimeFormatter.html#patterns">Supported Patterns</a> * * @param datetime datetime object * @param pattern Supported pattern * @return The formatted {@code TemporalAccessor} */ @Export public String format(TemporalAccessor datetime, String pattern) { DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern); return formatter.format(datetime); }
Example 3
Source File: OffsetTime.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 2 votes |
/** * Outputs this time as a {@code String} using the formatter. * <p> * This time will be passed to the formatter * {@link DateTimeFormatter#format(TemporalAccessor) print method}. * * @param formatter the formatter to use, not null * @return the formatted time string, not null * @throws DateTimeException if an error occurs during printing */ public String format(DateTimeFormatter formatter) { Jdk8Methods.requireNonNull(formatter, "formatter"); return formatter.format(this); }
Example 4
Source File: YearMonth.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 2 votes |
/** * Outputs this year-month as a {@code String} using the formatter. * <p> * This year-month will be passed to the formatter * {@link DateTimeFormatter#format(TemporalAccessor) print method}. * * @param formatter the formatter to use, not null * @return the formatted year-month string, not null * @throws DateTimeException if an error occurs during printing */ public String format(DateTimeFormatter formatter) { Jdk8Methods.requireNonNull(formatter, "formatter"); return formatter.format(this); }
Example 5
Source File: MonthDay.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 2 votes |
/** * Outputs this month-day as a {@code String} using the formatter. * <p> * This month-day will be passed to the formatter * {@link DateTimeFormatter#format(TemporalAccessor) print method}. * * @param formatter the formatter to use, not null * @return the formatted month-day string, not null * @throws DateTimeException if an error occurs during printing */ public String format(DateTimeFormatter formatter) { Jdk8Methods.requireNonNull(formatter, "formatter"); return formatter.format(this); }
Example 6
Source File: OffsetDateTime.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 2 votes |
/** * Outputs this date-time as a {@code String} using the formatter. * <p> * This date-time will be passed to the formatter * {@link DateTimeFormatter#format(TemporalAccessor) print method}. * * @param formatter the formatter to use, not null * @return the formatted date-time string, not null * @throws DateTimeException if an error occurs during printing */ public String format(DateTimeFormatter formatter) { Jdk8Methods.requireNonNull(formatter, "formatter"); return formatter.format(this); }
Example 7
Source File: LocalTime.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 2 votes |
/** * Outputs this time as a {@code String} using the formatter. * <p> * This time will be passed to the formatter * {@link DateTimeFormatter#format(TemporalAccessor) print method}. * * @param formatter the formatter to use, not null * @return the formatted time string, not null * @throws DateTimeException if an error occurs during printing */ public String format(DateTimeFormatter formatter) { Jdk8Methods.requireNonNull(formatter, "formatter"); return formatter.format(this); }
Example 8
Source File: ChronoZonedDateTime.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 2 votes |
/** * Outputs this date-time as a {@code String} using the formatter. * * @param formatter the formatter to use, not null * @return the formatted date-time string, not null * @throws DateTimeException if an error occurs during printing */ public String format(DateTimeFormatter formatter) { Jdk8Methods.requireNonNull(formatter, "formatter"); return formatter.format(this); }
Example 9
Source File: ChronoLocalDate.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 2 votes |
/** * Formats this date using the specified formatter. * <p> * This date will be passed to the formatter to produce a string. * <p> * The default implementation must behave as follows: * <pre> * return formatter.format(this); * </pre> * * @param formatter the formatter to use, not null * @return the formatted date string, not null * @throws DateTimeException if an error occurs during printing */ public String format(DateTimeFormatter formatter) { Jdk8Methods.requireNonNull(formatter, "formatter"); return formatter.format(this); }
Example 10
Source File: ChronoLocalDateTime.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 2 votes |
/** * Formats this date-time using the specified formatter. * <p> * This date-time will be passed to the formatter to produce a string. * <p> * The default implementation must behave as follows: * <pre> * return formatter.format(this); * </pre> * * @param formatter the formatter to use, not null * @return the formatted date-time string, not null * @throws DateTimeException if an error occurs during printing */ public String format(DateTimeFormatter formatter) { Jdk8Methods.requireNonNull(formatter, "formatter"); return formatter.format(this); }
Example 11
Source File: Year.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 2 votes |
/** * Outputs this year as a {@code String} using the formatter. * <p> * This year will be passed to the formatter * {@link DateTimeFormatter#format(TemporalAccessor) print method}. * * @param formatter the formatter to use, not null * @return the formatted year string, not null * @throws DateTimeException if an error occurs during printing */ public String format(DateTimeFormatter formatter) { Jdk8Methods.requireNonNull(formatter, "formatter"); return formatter.format(this); }