- 使用 Spring Initializr 创建 Spring Boot 应用程序
- 在Spring Boot中配置Cassandra
- 在 Spring Boot 上配置 Tomcat 连接池
- 将Camel消息路由到嵌入WildFly的Artemis上
本文整理了Java中java.time.Year
类的一些代码示例,展示了Year
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Year
类的具体详情如下:
包路径:java.time.Year
类名称:Year
[英]A year in the ISO-8601 calendar system, such as 2007.
Year is an immutable date-time object that represents a year. Any field that can be derived from a year can be obtained.
Note that years in the ISO chronology only align with years in the Gregorian-Julian system for modern years. Parts of Russia did not switch to the modern Gregorian/ISO rules until 1920. As such, historical years must be treated with caution.
This class does not store or represent a month, day, time or time-zone. For example, the value "2007" can be stored in a Year.
Years represented by this class follow the ISO-8601 standard and use the proleptic numbering system. Year 1 is preceded by year 0, then by year -1.
The ISO-8601 calendar system is the modern civil calendar system used today in most of the world. It is equivalent to the proleptic Gregorian calendar system, in which today's rules for leap years are applied for all time. For most applications written today, the ISO-8601 rules are entirely suitable. However, any application that makes use of historical dates, and requires them to be accurate will find the ISO-8601 approach unsuitable.
This class is immutable and thread-safe.
[中]ISO-8601日历系统中的一年,如2007年。
Year是表示年份的不可变日期时间对象。可以从一年中得到任何字段。
请注意,ISO年表中的年份仅与现代格里高利-朱利安体系中的年份一致。直到1920年,俄罗斯部分地区才改用现代的格里高利/ISO规则。因此,必须谨慎对待历史年份。
此类不存储或表示月、日、时间或时区。例如,值“2007”可以存储在一年内。
该类别所代表的年份遵循ISO-8601标准,并使用proleptic编号系统。第一年之前是第0年,然后是第1年。
ISO-8601日历系统是当今世界大部分地区使用的现代民用日历系统。它相当于公历的前身,即今天的闰年规则一直适用。对于今天编写的大多数应用程序,ISO-8601规则完全适用。然而,任何使用历史日期并要求其准确的应用程序都会发现ISO-8601方法不合适。
####实施者规范
这个类是不可变的,是线程安全的。
代码示例来源:origin: debezium/debezium
/**
* Converts a MySQL {@code YEAR} value to a {@link Year} object.
*
* @param inputStream the binary stream containing the raw binlog event data for the value
* @return the {@link Year} object
* @throws IOException if there is an error reading from the binlog event data
*/
protected static Serializable deserializeYear(ByteArrayInputStream inputStream) throws IOException {
return Year.of(1900 + inputStream.readInteger(1));
}
代码示例来源:origin: prestodb/presto
@Override
public void serialize(Year year, JsonGenerator generator, SerializerProvider provider) throws IOException
{
if (useTimestamp(provider)) {
generator.writeNumber(year.getValue());
} else {
String str = (_formatter == null) ? year.toString() : year.format(_formatter);
generator.writeString(str);
}
}
代码示例来源:origin: bootique/bootique
@Override
public Year deserialize(JsonParser parser, DeserializationContext context) throws IOException {
if (formatter == null) {
return Year.of(parser.getValueAsInt());
}
return Year.parse(parser.getValueAsString(), formatter);
}
}
代码示例来源:origin: kiegroup/optaplanner
@Test(expected = IllegalArgumentException.class)
public void remainderOnIncrementTypeExceedsMaximumYear() {
Year from = Year.of(Year.MIN_VALUE);
Year to = Year.of(Year.MAX_VALUE - 0);
assertNotEquals(0, (to.getValue() - from.getValue()) % 10); // Maximum Year range is not divisible by 10
assertNotNull(new TemporalValueRange<>(from, to, 1, ChronoUnit.DECADES));
}
代码示例来源:origin: apache/metron
@SuppressWarnings("rawtypes")
@Test
public void testTimestampParsing() throws ParseException {
JSONObject parsed = parser.parse(fireeyeMessage.getBytes()).get(0);
JSONParser parser = new JSONParser();
Map json = (Map) parser.parse(parsed.toJSONString());
long expectedTimestamp = ZonedDateTime.of(Year.now(ZoneOffset.UTC).getValue(), 3, 19, 5, 24, 39, 0, ZoneOffset.UTC).toInstant().toEpochMilli();
Assert.assertEquals(expectedTimestamp, json.get("timestamp"));
}
}
代码示例来源:origin: com.thoughtworks.xstream/xstream
return GregorianCalendar.from(ot.atDate(LocalDate.ofEpochDay(0)).atZoneSameInstant(ZoneId.systemDefault()));
} catch (final DateTimeParseException e) {
return GregorianCalendar.from(ot.atDate(LocalDate.ofEpochDay(0)).atZoneSameInstant(ZoneId.systemDefault()));
} catch (final DateTimeParseException e) {
final Year y = Year.from(ta);
final MonthDay md = MonthDay.from(ta);
final OffsetTime ot = OffsetTime.from(ta);
return GregorianCalendar.from(ot.atDate(y.atMonthDay(md)).atZoneSameInstant(ZoneId.systemDefault()));
} catch (final DateTimeParseException e) {
final Year y = Year.from(ta);
final MonthDay md = MonthDay.from(ta);
final OffsetTime ot = OffsetTime.from(ta);
return GregorianCalendar.from(ot.atDate(y.atMonthDay(md)).atZoneSameInstant(ZoneId.systemDefault()));
} catch (final DateTimeParseException e) {
final Year y = Year.from(ta);
final MonthDay md = MonthDay.from(ta);
return GregorianCalendar.from(y.atMonthDay(md).atStartOfDay(ZoneId.systemDefault()));
} catch (final DateTimeParseException e) {
final Year y = Year.parse(str);
return GregorianCalendar.from(y.atDay(1).atStartOfDay(ZoneId.systemDefault()));
} catch (final DateTimeParseException e) {
代码示例来源:origin: wildfly/wildfly
assertTrue(immutability.test(Duration.ZERO));
assertTrue(immutability.test(Instant.now()));
assertTrue(immutability.test(LocalDate.now()));
assertTrue(immutability.test(LocalDateTime.now()));
assertTrue(immutability.test(LocalTime.now()));
assertTrue(immutability.test(ValueRange.of(0L, 10L)));
assertTrue(immutability.test(WeekFields.ISO));
assertTrue(immutability.test(Year.now()));
assertTrue(immutability.test(YearMonth.now()));
assertTrue(immutability.test(ZoneOffset.UTC));
assertTrue(immutability.test(ZoneRules.of(ZoneOffset.UTC).nextTransition(Instant.now())));
assertTrue(immutability.test(ZoneOffsetTransitionRule.of(Month.JANUARY, 1, DayOfWeek.SUNDAY, LocalTime.MIDNIGHT, true, TimeDefinition.STANDARD, ZoneOffset.UTC, ZoneOffset.ofHours(1), ZoneOffset.ofHours(2))));
assertTrue(immutability.test(ZoneRules.of(ZoneOffset.UTC)));
assertTrue(immutability.test(ZonedDateTime.now()));
assertTrue(immutability.test(new JCIPImmutableObject()));
代码示例来源:origin: zsoltherpai/fluent-jdbc
private static void javaTime(Map<Class, ParamSetter> ss) {
reg(ss, Instant.class, (param, ps, i) -> ps.setTimestamp(i, timestamp(param)));
reg(ss, OffsetDateTime.class, (param, ps, i) -> ps.setTimestamp(i, timestamp(param.toInstant())));
reg(ss, ZonedDateTime.class, (param, ps, i) -> ps.setTimestamp(i, timestamp(param.toInstant())));
reg(ss, LocalDate.class, (param, ps, i) -> ps.setDate(i, java.sql.Date.valueOf(param)));
reg(ss, LocalTime.class, (param, ps, i) -> ps.setTime(i, java.sql.Time.valueOf(param)));
reg(ss, LocalDateTime.class, (param, ps, i) -> ps.setTimestamp(i, java.sql.Timestamp.valueOf(param)));
reg(ss, Year.class, (param, ps, i) -> ps.setDate(i, java.sql.Date.valueOf(LocalDate.of(param.getValue(), Month.JANUARY, 1))));
reg(ss, YearMonth.class, (param, ps, i) -> ps.setDate(i, java.sql.Date.valueOf(LocalDate.of(param.getYear(), param.getMonth(), 1))));
}
代码示例来源:origin: no.ssb.vtl/java-vtl-model
@Override
public Instant get() {
DateTimeFormatter formatter =
DateTimeFormatter.ofPattern("yyyy");
Year year = Year.parse(input, formatter);
return year.atDay(1).atStartOfDay(timeZone.toZoneId()).toInstant();
}
};
代码示例来源:origin: chhsiao90/nitmproxy
public static Certificate newCert(String parentCertFile, String keyFile, String host) {
try {
Date before = Date.from(Instant.now());
Date after = Date.from(Year.now().plus(3, ChronoUnit.YEARS).atDay(1).atStartOfDay(ZoneId.systemDefault()).toInstant());
X509CertificateHolder parent = readPemFromFile(parentCertFile);
PEMKeyPair pemKeyPair = readPemFromFile(keyFile);
KeyPair keyPair = new JcaPEMKeyConverter()
.setProvider(PROVIDER)
.getKeyPair(pemKeyPair);
X509v3CertificateBuilder x509 = new JcaX509v3CertificateBuilder(
parent.getSubject(),
new BigInteger(64, new SecureRandom()),
before,
after,
new X500Name("CN=" + host),
keyPair.getPublic());
ContentSigner signer = new JcaContentSignerBuilder("SHA256WithRSAEncryption")
.build(keyPair.getPrivate());
JcaX509CertificateConverter x509CertificateConverter = new JcaX509CertificateConverter()
.setProvider(PROVIDER);
return new Certificate(
keyPair,
x509CertificateConverter.getCertificate(x509.build(signer)),
x509CertificateConverter.getCertificate(parent));
} catch (Exception e) {
throw new IllegalStateException(e);
}
}
代码示例来源:origin: arnaudroger/SimpleFlatMapper
@Test
public void testJavaYear() throws Exception {
java.time.Year value = java.time.Year.now();
java.time.ZoneId zoneId = ZoneId.of("America/Los_Angeles");
newFieldMapperAndMapToPS(new ConstantGetter<Object, java.time.Year>(value), java.time.Year.class, new JavaZoneIdProperty(zoneId));
newFieldMapperAndMapToPS(NullGetter.<Object, java.time.Year>getter(), java.time.Year.class);
verify(ps).setDate(1, new java.sql.Date(value.atMonthDay(MonthDay.of(Month.JANUARY, 1)).atStartOfDay(zoneId).toInstant().toEpochMilli()));
verify(ps).setNull(2, Types.DATE);
}
//IFJAVA8_END
代码示例来源:origin: thymeleaf/thymeleaf-extras-java8time
Validate.notNull(defaultZoneId, "ZoneId cannot be null");
if (target instanceof Instant) {
return ZonedDateTime.ofInstant((Instant) target, defaultZoneId);
} else if (target instanceof LocalDate) {
return ZonedDateTime.of((LocalDate) target, LocalTime.MIDNIGHT, defaultZoneId);
} else if (target instanceof LocalDateTime) {
return ZonedDateTime.of((LocalDateTime) target, defaultZoneId);
} else if (target instanceof LocalTime) {
return ZonedDateTime.of(LocalDate.now(), (LocalTime) target, defaultZoneId);
} else if (target instanceof OffsetDateTime) {
return ((OffsetDateTime) target).toZonedDateTime();
} else if (target instanceof OffsetTime) {
LocalTime localTime = ((OffsetTime) target).toLocalTime();
return ZonedDateTime.of(LocalDate.now(), localTime, defaultZoneId);
} else if (target instanceof Year) {
LocalDate localDate = ((Year) target).atDay(1);
return ZonedDateTime.of(localDate, LocalTime.MIDNIGHT, defaultZoneId);
} else if (target instanceof YearMonth) {
LocalDate localDate = ((YearMonth) target).atDay(1);
return ZonedDateTime.of(localDate, LocalTime.MIDNIGHT, defaultZoneId);
} else if (target instanceof ZonedDateTime) {
代码示例来源:origin: apache/tinkerpop
addExtendedEntry(LocalDate.of(2016, 1, 1), "LocalDate", "", Compatibilities.UNTYPED_GRAPHSON.matchToArray());
addExtendedEntry(LocalDateTime.of(2016, 1, 1, 12, 30), "LocalDateTime", "", Compatibilities.UNTYPED_GRAPHSON.matchToArray());
addExtendedEntry(LocalTime.of(12, 30, 45), "LocalTime", "", Compatibilities.UNTYPED_GRAPHSON.matchToArray());
addExtendedEntry(Period.of(1, 6, 15), "Period", "The following example is a `Period` of one year, six months and fifteen days.", Compatibilities.UNTYPED_GRAPHSON.matchToArray());
addExtendedEntry(new Short("100"), "Short", "", Compatibilities.UNTYPED_GRAPHSON.matchToArray());
addExtendedEntry(Year.of(2016), "Year", "The following example is of the `Year` \"2016\".", Compatibilities.UNTYPED_GRAPHSON.matchToArray());
addExtendedEntry(YearMonth.of(2016, 6), "YearMonth", "The following example is a `YearMonth` of \"June 2016\"", Compatibilities.UNTYPED_GRAPHSON.matchToArray());
addExtendedEntry(ZonedDateTime.of(2016, 12, 23, 12, 12, 24, 36, ZoneId.of("GMT+2")), "ZonedDateTime", "", Compatibilities.UNTYPED_GRAPHSON.matchToArray());
addExtendedEntry(ZoneOffset.ofHoursMinutesSeconds(3, 6, 9), "ZoneOffset", "The following example is a `ZoneOffset` of three hours, six minutes, and nine seconds.", Compatibilities.UNTYPED_GRAPHSON.matchToArray());
代码示例来源:origin: odrotbohm/spring-restbucks
/**
* Returns the {@link LocalDate} the {@link CreditCard} expires.
*
* @return will never be {@literal null}.
*/
public LocalDate getExpirationDate() {
return LocalDate.of(expiryYear.getValue(), expiryMonth, 1);
}
代码示例来源:origin: nl.jqno.equalsverifier/equalsverifier
addValues(SimpleDateFormat.class, new SimpleDateFormat("yMd"), new SimpleDateFormat("dMy"), new SimpleDateFormat("yMd"));
addValues(TimeZone.class, TimeZone.getTimeZone("GMT+1"), TimeZone.getTimeZone("GMT+2"), TimeZone.getTimeZone("GMT+1"));
addValues(Year.class, Year.of(2000), Year.of(2010), Year.of(2000));
addValues(YearMonth.class,
YearMonth.of(2000, 1),
YearMonth.of(2010, 12),
YearMonth.of(2000, 1));
addValues(ZoneId.class, ZoneId.of("+1"), ZoneId.of("-10"), ZoneId.of("+1"));
addValues(ZoneOffset.class, ZoneOffset.ofHours(1), ZoneOffset.ofHours(-1), ZoneOffset.ofHours(1));
addValues(ZonedDateTime.class,
ZonedDateTime.parse("2017-12-13T10:15:30+01:00"),
ZonedDateTime.parse("2016-11-12T09:14:29-01:00"),
ZonedDateTime.parse("2017-12-13T10:15:30+01:00"));
代码示例来源:origin: edu.byu.hbll/time
temporalAccessor = ((LocalDate) temporalAccessor).plusDays(1L);
} else if (temporalAccessor instanceof YearMonth) {
temporalAccessor = ((YearMonth) temporalAccessor).atDay(1).plusMonths(1L);
} else if (temporalAccessor instanceof Year) {
temporalAccessor = ((Year) temporalAccessor).atDay(1).plusYears(1L);
代码示例来源:origin: crawler-commons/crawler-commons
LocalDate ldt = null;
if (ta.isSupported(ChronoField.DAY_OF_MONTH)) {
ldt = LocalDate.from(ta);
} else if (ta.isSupported(ChronoField.MONTH_OF_YEAR)) {
ldt = YearMonth.from(ta).atDay(1);
} else if (ta.isSupported(ChronoField.YEAR)) {
ldt = Year.from(ta).atDay(1);
return ldt.atStartOfDay(TIME_ZONE_UTC);
代码示例来源:origin: nl.vpro.shared/vpro-shared-xml
@Override
public Temporal unmarshal(String dateValue) {
if (dateValue == null) {
return null;
}
try {
return LocalDate.parse(dateValue);
} catch (DateTimeParseException pe) {
return Year.parse(dateValue);
}
}
代码示例来源:origin: org.kie/kie-dmn-feel
@Test
public void invokeYearLocalDate() {
FunctionTestUtil.assertResult(
yamFunction.invoke(LocalDate.of(2017, 6, 12), Year.of(2020)),
Period.of(2, 6, 0));
}
代码示例来源:origin: edu.byu.hbll/time
temporalAccessor = ((Year) temporalAccessor).atDay(1);
} else if (temporalAccessor instanceof YearMonth) {
temporalAccessor = ((YearMonth) temporalAccessor).atDay(1);
temporalAccessor = ((LocalDate) temporalAccessor).atStartOfDay();
在尝试 time 的 python 执行时,我发现在一条语句中两次调用 time.time() 时出现奇怪的行为。在语句执行期间获取time.time() 有一个非常小的处理延迟。 例如time.ti
我要疯了。对于我的生活,我无法弄清楚为什么以下代码会导致 Unity 在我按下播放键后立即卡住。这是一个空的项目,脚本附加到一个空的游戏对象。在控制台中,什么也没有出现,甚至没有出现初始的 Debug
我要疯了。对于我的生活,我无法弄清楚为什么以下代码会导致 Unity 在我按下播放键后立即卡住。这是一个空的项目,脚本附加到一个空的游戏对象。在控制台中,什么也没有出现,甚至没有出现初始的 Debug
我不明白为什么下面的结果是一样的。我预计第一个结果是指针地址。 func print(t *time.Time) { fmt.Println(t) // 2009-11-10 23:00:00
Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:54:40) [MSC v.1900 64 bit (AMD64)] on win32 Type "help
当我有一个time.Time时: // January, 29th t, _ := time.Parse("2006-01-02", "2016-01-29") 如何获得代表 1 月 31 日的 ti
首先,我意识到不推荐使用 time with time zone。我要使用它是因为我将多个 time with time zone 值与我当前的系统时间进行比较,而不管是哪一天。 IE。用户说每天 0
长期以来,在 Rust 中精确测量时间的标准方法是 time crate 及其 time::precise_time_ns功能。但是,time crate 现在已被弃用,std 库有 std::tim
我正在我学校的一个科学集群上运行我的有限差分程序。该程序使用 openmpi 来并行化代码。 当程序连续运行时,我得到: real 78m40.592s user 78m34.920s s
尽管它们已被弃用并且有比 time 更好的模块(即 timeit),但我想知道这两个函数 time 之间的区别.clock() 和 time.time()。 从后者 (time.time()) 开始,
这个问题在这里已经有了答案: Python's time.clock() vs. time.time() accuracy? (16 个答案) 关闭 6 年前。 我认为两者都衡量时间量?但是他们返回
我正在尝试测试 http 请求处理代码块在我的 Flask Controller 中需要多长时间,这是我使用的示例代码: cancelled = [] t0 = time.time() t1 = ti
运行 python 的计算机时钟(Windows 或 Linux)时会发生什么自动更改并调用 time.time()? 我读到,当时钟手动更改为过去的某个值时,time.time() 的值会变小。 最
我有一个结构可能无法在其字段之一上设置 time.Time 值。测试无效性时,我不能使用 nil 或 0。time.Unix(0,0) 也不相同。我想到了这个: var emptyTime time.
我有一个打算用数据库记录填充的结构,其中一个日期时间列可以为空: type Reminder struct { Id int CreatedAt time.Time
问题陈述:通过匹配其百分比随机执行各种命令。比如执行 CommandA 50% 的时间和 commandB 25% 的时间和 commandC 15% 的时间等等,总百分比应该是 100%。 我的问题
我正在使用 laravel 6。我在同一个应用程序中有类似的 Controller 和类似的 View ,它工作正常。对比之后还是找不到错误。 Facade\Ignition\Exceptions\V
我需要用 ("%m/%d/%Y %H:%M:%S") 格式表示时间,我得到的浮点值是 time.time(). 我已经有了一个 time.time() 形式的值。例如,我已经有一个值,我每 0.3 秒
我正在使用以下方法获取 utc 日期时间: import datetime import time from pytz import timezone now_utc = datetime.datet
我在 Ubuntu 上使用 time.clock 和 time.time 为一段 python 代码计时: clock elapsed time: 8.770 s time elapsed time
我是一名优秀的程序员,十分优秀!