Java Code Examples for org.threeten.bp.format.DateTimeFormatter#ofPattern()

The following examples show how to use org.threeten.bp.format.DateTimeFormatter#ofPattern() . 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: BrapiObservation.java    From Field-Book with GNU General Public License v2.0 5 votes vote down vote up
private OffsetDateTime convertTime(String time) {
    OffsetDateTime converted = null;
    try {
        //TODO: locale
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSXXX");
        converted = OffsetDateTime.parse(time, formatter);
    } catch (DateTimeParseException e) {
        e.printStackTrace();
    } finally {
        return converted;
    }

}
 
Example 2
Source File: TestOffsetDateTime.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void factory_parse_formatter_nullText() {
    DateTimeFormatter f = DateTimeFormatter.ofPattern("u M d H m s");
    OffsetDateTime.parse((String) null, f);
}
 
Example 3
Source File: TestMonthDay.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void factory_parse_formatter_nullText() {
    DateTimeFormatter f = DateTimeFormatter.ofPattern("M d");
    MonthDay.parse((String) null, f);
}
 
Example 4
Source File: TestOffsetTime.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test
public void factory_parse_formatter() {
    DateTimeFormatter f = DateTimeFormatter.ofPattern("H m s XXX");
    OffsetTime test = OffsetTime.parse("11 30 0 +01:00", f);
    assertEquals(test, OffsetTime.of(LocalTime.of(11, 30), ZoneOffset.ofHours(1)));
}
 
Example 5
Source File: TestYear.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void factory_parse_formatter_nullText() {
    DateTimeFormatter f = DateTimeFormatter.ofPattern("u");
    Year.parse((String) null, f);
}
 
Example 6
Source File: TestLocalTime.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void factory_parse_formatter_nullText() {
    DateTimeFormatter f = DateTimeFormatter.ofPattern("H m s");
    LocalTime.parse((String) null, f);
}
 
Example 7
Source File: TestYearMonth.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test
public void factory_parse_formatter() {
    DateTimeFormatter f = DateTimeFormatter.ofPattern("u M");
    YearMonth test = YearMonth.parse("2010 12", f);
    assertEquals(test, YearMonth.of(2010, 12));
}
 
Example 8
Source File: TestLocalDateTime.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test
public void test_format_formatter() {
    DateTimeFormatter f = DateTimeFormatter.ofPattern("y M d H m s");
    String t = LocalDateTime.of(2010, 12, 3, 11, 30, 45).format(f);
    assertEquals(t, "2010 12 3 11 30 45");
}
 
Example 9
Source File: TestLocalDate.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void factory_parse_formatter_nullText() {
    DateTimeFormatter f = DateTimeFormatter.ofPattern("u M d");
    LocalDate.parse((String) null, f);
}
 
Example 10
Source File: TestLocalDateTime.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test
public void factory_parse_formatter() {
    DateTimeFormatter f = DateTimeFormatter.ofPattern("u M d H m s");
    LocalDateTime test = LocalDateTime.parse("2010 12 3 11 30 45", f);
    assertEquals(test, LocalDateTime.of(2010, 12, 3, 11, 30, 45));
}
 
Example 11
Source File: TestZonedDateTime.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test
public void test_format_formatter() {
    DateTimeFormatter f = DateTimeFormatter.ofPattern("y M d H m s");
    String t = ZonedDateTime.of(dateTime(2010, 12, 3, 11, 30), ZONE_PARIS).format(f);
    assertEquals(t, "2010 12 3 11 30 0");
}
 
Example 12
Source File: TestOffsetDateTime.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test
public void test_format_formatter() {
    DateTimeFormatter f = DateTimeFormatter.ofPattern("y M d H m s");
    String t = OffsetDateTime.of(LocalDate.of(2010, 12, 3), LocalTime.of(11, 30), OFFSET_PONE).format(f);
    assertEquals(t, "2010 12 3 11 30 0");
}
 
Example 13
Source File: TestYearMonth.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void factory_parse_formatter_nullText() {
    DateTimeFormatter f = DateTimeFormatter.ofPattern("u M");
    YearMonth.parse((String) null, f);
}
 
Example 14
Source File: TestOffsetTime.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test
public void test_format_formatter() {
    DateTimeFormatter f = DateTimeFormatter.ofPattern("H m s");
    String t = OffsetTime.of(LocalTime.of(11, 30), OFFSET_PONE).format(f);
    assertEquals(t, "11 30 0");
}
 
Example 15
Source File: DateFormatDayFormatter.java    From material-calendarview with MIT License 4 votes vote down vote up
/**
 * Format using a default format
 */
public DateFormatDayFormatter() {
  this(DateTimeFormatter.ofPattern(DEFAULT_FORMAT, Locale.getDefault()));
}
 
Example 16
Source File: TestLocalDate.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test
public void test_format_formatter() {
    DateTimeFormatter f = DateTimeFormatter.ofPattern("y M d");
    String t = LocalDate.of(2010, 12, 3).format(f);
    assertEquals(t, "2010 12 3");
}
 
Example 17
Source File: TestYearMonth.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test
public void test_format_formatter() {
    DateTimeFormatter f = DateTimeFormatter.ofPattern("y M");
    String t = YearMonth.of(2010, 12).format(f);
    assertEquals(t, "2010 12");
}
 
Example 18
Source File: TestMonthDay.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test
public void test_format_formatter() {
    DateTimeFormatter f = DateTimeFormatter.ofPattern("M d");
    String t = MonthDay.of(12, 3).format(f);
    assertEquals(t, "12 3");
}
 
Example 19
Source File: AppSettings.java    From openlauncher with Apache License 2.0 4 votes vote down vote up
public DateTimeFormatter getUserDateFormat() {
    String line1 = getString(R.string.pref_key__date_bar_date_format_custom_1, rstr(R.string.pref_default__date_bar_date_format_custom_1));
    String line2 = getString(R.string.pref_key__date_bar_date_format_custom_2, rstr(R.string.pref_default__date_bar_date_format_custom_2));

    return DateTimeFormatter.ofPattern(line1 +  "'\n'" + line2);
}
 
Example 20
Source File: DateTime.java    From yql-plus with Apache License 2.0 2 votes vote down vote up
/**
 * 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);
}