• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java TemporalAccessor类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.threeten.bp.temporal.TemporalAccessor的典型用法代码示例。如果您正苦于以下问题:Java TemporalAccessor类的具体用法?Java TemporalAccessor怎么用?Java TemporalAccessor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



TemporalAccessor类属于org.threeten.bp.temporal包,在下文中一共展示了TemporalAccessor类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: CustomInstantDeserializer

import org.threeten.bp.temporal.TemporalAccessor; //导入依赖的package包/类
protected CustomInstantDeserializer(Class<T> supportedType,
                  DateTimeFormatter parser,
                  Function<TemporalAccessor, T> parsedToValue,
                  Function<FromIntegerArguments, T> fromMilliseconds,
                  Function<FromDecimalArguments, T> fromNanoseconds,
                  BiFunction<T, ZoneId, T> adjust) {
  super(supportedType, parser);
  this.parsedToValue = parsedToValue;
  this.fromMilliseconds = fromMilliseconds;
  this.fromNanoseconds = fromNanoseconds;
  this.adjust = adjust == null ? new BiFunction<T, ZoneId, T>() {
    @Override
    public T apply(T t, ZoneId zoneId) {
      return t;
    }
  } : adjust;
}
 
开发者ID:cliffano,项目名称:swaggy-jenkins,代码行数:18,代码来源:CustomInstantDeserializer.java


示例2: from

import org.threeten.bp.temporal.TemporalAccessor; //导入依赖的package包/类
/**
 * Obtains an instance of {@code OffsetDateTime} from a temporal object.
 * <p>
 * A {@code TemporalAccessor} represents some form of date and time information.
 * This factory converts the arbitrary temporal object to an instance of {@code OffsetDateTime}.
 * <p>
 * The conversion extracts and combines {@code LocalDateTime} and {@code ZoneOffset}.
 * If that fails it will try to extract and combine {@code Instant} and {@code ZoneOffset}.
 * <p>
 * This method matches the signature of the functional interface {@link TemporalQuery}
 * allowing it to be used in queries via method reference, {@code OffsetDateTime::from}.
 *
 * @param temporal  the temporal object to convert, not null
 * @return the offset date-time, not null
 * @throws DateTimeException if unable to convert to an {@code OffsetDateTime}
 */
public static OffsetDateTime from(TemporalAccessor temporal) {
    if (temporal instanceof OffsetDateTime) {
        return (OffsetDateTime) temporal;
    }
    try {
        ZoneOffset offset = ZoneOffset.from(temporal);
        try {
            LocalDateTime ldt = LocalDateTime.from(temporal);
            return OffsetDateTime.of(ldt, offset);
        } catch (DateTimeException ignore) {
            Instant instant = Instant.from(temporal);
            return OffsetDateTime.ofInstant(instant, offset);
        }
    } catch (DateTimeException ex) {
        throw new DateTimeException("Unable to obtain OffsetDateTime from TemporalAccessor: " +
                temporal + ", type " + temporal.getClass().getName());
    }
}
 
开发者ID:ThreeTen,项目名称:threetenbp,代码行数:35,代码来源:OffsetDateTime.java


示例3: test_print_isoOffsetTime

import org.threeten.bp.temporal.TemporalAccessor; //导入依赖的package包/类
@Test(dataProvider="sample_isoOffsetTime")
public void test_print_isoOffsetTime(
        Integer hour, Integer min, Integer sec, Integer nano, String offsetId, String zoneId,
        String expected, Class<?> expectedEx) {
    TemporalAccessor test = buildAccessor(null, null, null, hour, min, sec, nano, offsetId, zoneId);
    if (expectedEx == null) {
        assertEquals(DateTimeFormatter.ISO_OFFSET_TIME.format(test), expected);
    } else {
        try {
            DateTimeFormatter.ISO_OFFSET_TIME.format(test);
            fail();
        } catch (Exception ex) {
            assertTrue(expectedEx.isInstance(ex));
        }
    }
}
 
开发者ID:ThreeTen,项目名称:threetenbp,代码行数:17,代码来源:TestDateTimeFormatters.java


示例4: crossCheck

import org.threeten.bp.temporal.TemporalAccessor; //导入依赖的package包/类
private void crossCheck(TemporalAccessor temporal) {
    Iterator<Entry<TemporalField, Long>> it = fieldValues.entrySet().iterator();
    while (it.hasNext()) {
        Entry<TemporalField, Long> entry = it.next();
        TemporalField field = entry.getKey();
        long value = entry.getValue();
        if (temporal.isSupported(field)) {
            long temporalValue;
            try {
                temporalValue = temporal.getLong(field);
            } catch (RuntimeException ex) {
                continue;
            }
            if (temporalValue != value) {
                throw new DateTimeException("Cross check failed: " +
                        field + " " + temporalValue + " vs " + field + " " + value);
            }
            it.remove();
        }
    }
}
 
开发者ID:ThreeTen,项目名称:threetenbp,代码行数:22,代码来源:DateTimeBuilder.java


示例5: formatTo

import org.threeten.bp.temporal.TemporalAccessor; //导入依赖的package包/类
/**
 * Formats a date-time object to an {@code Appendable} using this formatter.
 * <p>
 * This formats the date-time to the specified destination.
 * {@link Appendable} is a general purpose interface that is implemented by all
 * key character output classes including {@code StringBuffer}, {@code StringBuilder},
 * {@code PrintStream} and {@code Writer}.
 * <p>
 * Although {@code Appendable} methods throw an {@code IOException}, this method does not.
 * Instead, any {@code IOException} is wrapped in a runtime exception.
 *
 * @param temporal  the temporal object to print, not null
 * @param appendable  the appendable to print to, not null
 * @throws DateTimeException if an error occurs during formatting
 */
public void formatTo(TemporalAccessor temporal, Appendable appendable) {
    Jdk8Methods.requireNonNull(temporal, "temporal");
    Jdk8Methods.requireNonNull(appendable, "appendable");
    try {
        DateTimePrintContext context = new DateTimePrintContext(temporal, this);
        if (appendable instanceof StringBuilder) {
            printerParser.print(context, (StringBuilder) appendable);
        } else {
            // buffer output to avoid writing to appendable in case of error
            StringBuilder buf = new StringBuilder(32);
            printerParser.print(context, buf);
            appendable.append(buf);
        }
    } catch (IOException ex) {
        throw new DateTimeException(ex.getMessage(), ex);
    }
}
 
开发者ID:ThreeTen,项目名称:threetenbp,代码行数:33,代码来源:DateTimeFormatter.java


示例6: format

import org.threeten.bp.temporal.TemporalAccessor; //导入依赖的package包/类
@Override
public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos) {
    Jdk8Methods.requireNonNull(obj, "obj");
    Jdk8Methods.requireNonNull(toAppendTo, "toAppendTo");
    Jdk8Methods.requireNonNull(pos, "pos");
    if (obj instanceof TemporalAccessor == false) {
        throw new IllegalArgumentException("Format target must implement TemporalAccessor");
    }
    pos.setBeginIndex(0);
    pos.setEndIndex(0);
    try {
        formatter.formatTo((TemporalAccessor) obj, toAppendTo);
    } catch (RuntimeException ex) {
        throw new IllegalArgumentException(ex.getMessage(), ex);
    }
    return toAppendTo;
}
 
开发者ID:ThreeTen,项目名称:threetenbp,代码行数:18,代码来源:DateTimeFormatter.java


示例7: from

import org.threeten.bp.temporal.TemporalAccessor; //导入依赖的package包/类
/**
 * Obtains an instance of {@code LocalDateTime} from a temporal object.
 * <p>
 * A {@code TemporalAccessor} represents some form of date and time information.
 * This factory converts the arbitrary temporal object to an instance of {@code LocalDateTime}.
 * <p>
 * The conversion extracts and combines {@code LocalDate} and {@code LocalTime}.
 * <p>
 * This method matches the signature of the functional interface {@link TemporalQuery}
 * allowing it to be used as a query via method reference, {@code LocalDateTime::from}.
 *
 * @param temporal  the temporal object to convert, not null
 * @return the local date-time, not null
 * @throws DateTimeException if unable to convert to a {@code LocalDateTime}
 */
public static LocalDateTime from(TemporalAccessor temporal) {
    if (temporal instanceof LocalDateTime) {
        return (LocalDateTime) temporal;
    } else if (temporal instanceof ZonedDateTime) {
        return ((ZonedDateTime) temporal).toLocalDateTime();
    }
    try {
        LocalDate date = LocalDate.from(temporal);
        LocalTime time = LocalTime.from(temporal);
        return new LocalDateTime(date, time);
    } catch (DateTimeException ex) {
        throw new DateTimeException("Unable to obtain LocalDateTime from TemporalAccessor: " +
                temporal + ", type " + temporal.getClass().getName());
    }
}
 
开发者ID:ThreeTen,项目名称:threetenbp,代码行数:31,代码来源:LocalDateTime.java


示例8: test_print_isoLocalDate

import org.threeten.bp.temporal.TemporalAccessor; //导入依赖的package包/类
@Test(dataProvider="sample_isoLocalDate")
public void test_print_isoLocalDate(
        Integer year, Integer month, Integer day, String offsetId, String zoneId,
        String expected, Class<?> expectedEx) {
    TemporalAccessor test = buildAccessor(year, month, day, null, null, null, null, offsetId, zoneId);
    if (expectedEx == null) {
        assertEquals(DateTimeFormatter.ISO_LOCAL_DATE.format(test), expected);
    } else {
        try {
            DateTimeFormatter.ISO_LOCAL_DATE.format(test);
            fail();
        } catch (Exception ex) {
            assertTrue(expectedEx.isInstance(ex));
        }
    }
}
 
开发者ID:ThreeTen,项目名称:threetenbp,代码行数:17,代码来源:TestDateTimeFormatters.java


示例9: test_print_isoTime

import org.threeten.bp.temporal.TemporalAccessor; //导入依赖的package包/类
@Test(dataProvider="sample_isoTime")
public void test_print_isoTime(
        Integer hour, Integer min, Integer sec, Integer nano, String offsetId, String zoneId,
        String expected, Class<?> expectedEx) {
    TemporalAccessor test = buildAccessor(null, null, null, hour, min, sec, nano, offsetId, zoneId);
    if (expectedEx == null) {
        assertEquals(DateTimeFormatter.ISO_TIME.format(test), expected);
    } else {
        try {
            DateTimeFormatter.ISO_TIME.format(test);
            fail();
        } catch (Exception ex) {
            assertTrue(expectedEx.isInstance(ex));
        }
    }
}
 
开发者ID:ThreeTen,项目名称:threetenbp,代码行数:17,代码来源:TestDateTimeFormatters.java


示例10: test_print_isoDate

import org.threeten.bp.temporal.TemporalAccessor; //导入依赖的package包/类
@Test(dataProvider="sample_isoDate")
public void test_print_isoDate(
        Integer year, Integer month, Integer day, String offsetId, String zoneId,
        String expected, Class<?> expectedEx) {
    TemporalAccessor test = buildAccessor(year, month, day, null, null, null, null, offsetId, zoneId);
    if (expectedEx == null) {
        assertEquals(DateTimeFormatter.ISO_DATE.format(test), expected);
    } else {
        try {
            DateTimeFormatter.ISO_DATE.format(test);
            fail();
        } catch (Exception ex) {
            assertTrue(expectedEx.isInstance(ex));
        }
    }
}
 
开发者ID:ThreeTen,项目名称:threetenbp,代码行数:17,代码来源:TestDateTimeFormatters.java


示例11: zonedDateTime

import org.threeten.bp.temporal.TemporalAccessor; //导入依赖的package包/类
/**
 * Obtains a zoned date-time in this chronology from another temporal object.
 * <p>
 * This creates a date-time in this chronology based on the specified {@code TemporalAccessor}.
 * <p>
 * This should obtain a {@code ZoneId} using {@link ZoneId#from(TemporalAccessor)}.
 * The date-time should be obtained by obtaining an {@code Instant}.
 * If that fails, the local date-time should be used.
 *
 * @param temporal  the temporal object to convert, not null
 * @return the zoned date-time in this chronology, not null
 * @throws DateTimeException if unable to create the date-time
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
public ChronoZonedDateTime<?> zonedDateTime(TemporalAccessor temporal) {
    try {
        ZoneId zone = ZoneId.from(temporal);
        try {
            Instant instant = Instant.from(temporal);
            return zonedDateTime(instant, zone);

        } catch (DateTimeException ex1) {
            ChronoLocalDateTime cldt = localDateTime(temporal);
            ChronoLocalDateTimeImpl cldtImpl = ensureChronoLocalDateTime(cldt);
            return ChronoZonedDateTimeImpl.ofBest(cldtImpl, zone, null);
        }
    } catch (DateTimeException ex) {
        throw new DateTimeException("Unable to obtain ChronoZonedDateTime from TemporalAccessor: " + temporal.getClass(), ex);
    }
}
 
开发者ID:ThreeTen,项目名称:threetenbp,代码行数:31,代码来源:Chronology.java


示例12: parseSecs

import org.threeten.bp.temporal.TemporalAccessor; //导入依赖的package包/类
private int parseSecs(String str) {
    if (str.equals("-")) {
        return 0;
    }
    int pos = 0;
    if (str.startsWith("-")) {
        pos = 1;
    }
    ParsePosition pp = new ParsePosition(pos);
    TemporalAccessor parsed = TIME_PARSER.parseUnresolved(str, pp);
    if (parsed == null || pp.getErrorIndex() >= 0) {
        throw new IllegalArgumentException(str);
    }
    long hour = parsed.getLong(HOUR_OF_DAY);
    Long min = (parsed.isSupported(MINUTE_OF_HOUR) ? parsed.getLong(MINUTE_OF_HOUR) : null);
    Long sec = (parsed.isSupported(SECOND_OF_MINUTE) ? parsed.getLong(SECOND_OF_MINUTE) : null);
    int secs = (int) (hour * 60 * 60 + (min != null ? min : 0) * 60 + (sec != null ? sec : 0));
    if (pos == 1) {
        secs = -secs;
    }
    return secs;
}
 
开发者ID:ThreeTen,项目名称:threetenbp,代码行数:23,代码来源:TzdbZoneRulesCompiler.java


示例13: test_parse_fromField_InstantSeconds_NanoOfSecond

import org.threeten.bp.temporal.TemporalAccessor; //导入依赖的package包/类
@Test
public void test_parse_fromField_InstantSeconds_NanoOfSecond() {
    DateTimeFormatter fmt = new DateTimeFormatterBuilder()
        .appendValue(INSTANT_SECONDS).appendLiteral('.').appendValue(NANO_OF_SECOND).toFormatter();
    TemporalAccessor acc = fmt.parse("86402.123456789");
    Instant expected = Instant.ofEpochSecond(86402, 123456789);
    assertEquals(acc.isSupported(INSTANT_SECONDS), true);
    assertEquals(acc.isSupported(NANO_OF_SECOND), true);
    assertEquals(acc.isSupported(MICRO_OF_SECOND), true);
    assertEquals(acc.isSupported(MILLI_OF_SECOND), true);
    assertEquals(acc.getLong(INSTANT_SECONDS), 86402L);
    assertEquals(acc.getLong(NANO_OF_SECOND), 123456789L);
    assertEquals(acc.getLong(MICRO_OF_SECOND), 123456L);
    assertEquals(acc.getLong(MILLI_OF_SECOND), 123L);
    assertEquals(Instant.from(acc), expected);
}
 
开发者ID:ThreeTen,项目名称:threetenbp,代码行数:17,代码来源:TestDateTimeParsing.java


示例14: test_print_isoDateTime

import org.threeten.bp.temporal.TemporalAccessor; //导入依赖的package包/类
@Test(dataProvider="sample_isoDateTime")
public void test_print_isoDateTime(
        Integer year, Integer month, Integer day,
        Integer hour, Integer min, Integer sec, Integer nano, String offsetId, String zoneId,
        String expected, Class<?> expectedEx) {
    TemporalAccessor test = buildAccessor(year, month, day, hour, min, sec, nano, offsetId, zoneId);
    if (expectedEx == null) {
        assertEquals(DateTimeFormatter.ISO_DATE_TIME.format(test), expected);
    } else {
        try {
            DateTimeFormatter.ISO_DATE_TIME.format(test);
            fail();
        } catch (Exception ex) {
            assertTrue(expectedEx.isInstance(ex));
        }
    }
}
 
开发者ID:ThreeTen,项目名称:threetenbp,代码行数:18,代码来源:TestDateTimeFormatters.java


示例15: lookup

import org.threeten.bp.temporal.TemporalAccessor; //导入依赖的package包/类
private static void lookup() {
        LocalDate date = LocalDate.now();
        LocalTime time = LocalTime.now();
        LocalDateTime dateTime = LocalDateTime.now();
//        System.out.println(LocalDateField.DAY_OF_MONTH.getDateRules().get(date));
//        System.out.println(LocalDateField.MONTH_OF_YEAR.getDateRules().get(date));
//        System.out.println(LocalDateField.YEAR.getDateRules().get(date));
//        System.out.println(QuarterYearField.QUARTER_OF_YEAR.getDateRules().get(date));
//        System.out.println(QuarterYearField.MONTH_OF_QUARTER.getDateRules().get(date));
//        System.out.println(QuarterYearField.DAY_OF_QUARTER.getDateRules().get(date));

        output(date, ChronoField.DAY_OF_MONTH);
        output(date, ChronoField.MONTH_OF_YEAR);
        output(date, ChronoField.YEAR);

        output(dateTime, ChronoField.DAY_OF_MONTH);
        output(time, ChronoField.HOUR_OF_DAY);
        output(time, ChronoField.MINUTE_OF_HOUR);

        TemporalAccessor cal = date;
        System.out.println("DoM: " + cal.get(DAY_OF_MONTH));
    }
 
开发者ID:ThreeTen,项目名称:threetenbp,代码行数:23,代码来源:UsabilityBasic.java


示例16: setupBuildSection

import org.threeten.bp.temporal.TemporalAccessor; //导入依赖的package包/类
private void setupBuildSection() {
  buildNameView.setText(BuildConfig.VERSION_NAME);
  buildCodeView.setText(String.valueOf(BuildConfig.VERSION_CODE));
  buildShaView.setText(BuildConfig.GIT_SHA);

  TemporalAccessor buildTime = Instant.ofEpochSecond(BuildConfig.GIT_TIMESTAMP);
  buildDateView.setText(DATE_DISPLAY_FORMAT.format(buildTime));
}
 
开发者ID:rogues-dev,项目名称:superglue,代码行数:9,代码来源:DebugView.java


示例17: from

import org.threeten.bp.temporal.TemporalAccessor; //导入依赖的package包/类
/**
 * Obtains a flexi date-time, specifying an arbitrary temporal.
 * <p>
 * This factory examines the temporal, extracting the date, time, offset and zone.
 * 
 * @param temporal  the temporal, not null
 * @return the date-time, not null
 */
public static FlexiDateTime from(TemporalAccessor temporal) {
  ArgumentChecker.notNull(temporal, "calendrical");
  LocalDate date = LocalDate.from(temporal);
  LocalTime time;
  try {
    time = LocalTime.from(temporal);
  } catch (Exception ex) {
    time = null;
  }
  ZoneId zone = temporal.query(TemporalQueries.zone());
  return new FlexiDateTime(date, time, zone);
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:21,代码来源:FlexiDateTime.java


示例18: setupBuildSection

import org.threeten.bp.temporal.TemporalAccessor; //导入依赖的package包/类
private void setupBuildSection() {
    buildNameView.setText(BuildConfig.VERSION_NAME);
    buildCodeView.setText(String.valueOf(BuildConfig.VERSION_CODE));
    buildShaView.setText(BuildConfig.GIT_SHA);

    TemporalAccessor buildTime = Instant.ofEpochSecond(BuildConfig.GIT_TIMESTAMP);
    buildDateView.setText(DATE_DISPLAY_FORMAT.format(buildTime));
}
 
开发者ID:LiveTyping,项目名称:u2020-mvp,代码行数:9,代码来源:DebugView.java


示例19: test_appendValue_subsequent2_parse3

import org.threeten.bp.temporal.TemporalAccessor; //导入依赖的package包/类
@Test
public void test_appendValue_subsequent2_parse3() throws Exception {
    builder.appendValue(MONTH_OF_YEAR, 1, 2, SignStyle.NORMAL).appendValue(DAY_OF_MONTH, 2);
    DateTimeFormatter f = builder.toFormatter();
    assertEquals(f.toString(), "Value(MonthOfYear,1,2,NORMAL)Value(DayOfMonth,2)");
    TemporalAccessor cal = f.parseUnresolved("123", new ParsePosition(0));
    assertEquals(cal.get(MONTH_OF_YEAR), 1);
    assertEquals(cal.get(DAY_OF_MONTH), 23);
}
 
开发者ID:ThreeTen,项目名称:threetenbp,代码行数:10,代码来源:TestDateTimeFormatterBuilder.java


示例20: test_toFormat_parseObject_StringParsePosition_parseError

import org.threeten.bp.temporal.TemporalAccessor; //导入依赖的package包/类
@Test
public void test_toFormat_parseObject_StringParsePosition_parseError() throws Exception {
    DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
    Format format = test.toFormat();
    ParsePosition pos = new ParsePosition(0);
    TemporalAccessor result = (TemporalAccessor) format.parseObject("ONEXXX", pos);
    assertEquals(pos.getIndex(), 0);  // TODO: is this right?
    assertEquals(pos.getErrorIndex(), 3);
    assertEquals(result, null);
}
 
开发者ID:ThreeTen,项目名称:threetenbp,代码行数:11,代码来源:TestDateTimeFormatter.java



注:本文中的org.threeten.bp.temporal.TemporalAccessor类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ListEditor类代码示例发布时间:2022-05-23
下一篇:
Java LuaNil类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap