本文整理了Java中java.time.LocalDateTime.with()
方法的一些代码示例,展示了LocalDateTime.with()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LocalDateTime.with()
方法的具体详情如下:
包路径:java.time.LocalDateTime
类名称:LocalDateTime
方法名:with
[英]Returns a copy of this date-time with the new date and time, checking to see if a new object is in fact required.
[中]返回带有新日期和时间的此日期时间的副本,检查是否确实需要新对象。
代码示例来源:origin: org.postgresql/postgresql
/**
* Parse a string and return a LocalDateTime representing its value.
*
* @param s The ISO formated date string to parse.
* @return null if s is null or a LocalDateTime of the parsed string s.
* @throws SQLException if there is a problem parsing s.
*/
public LocalDateTime toLocalDateTime(String s) throws SQLException {
if (s == null) {
return null;
}
int slen = s.length();
// convert postgres's infinity values to internal infinity magic value
if (slen == 8 && s.equals("infinity")) {
return LocalDateTime.MAX;
}
if (slen == 9 && s.equals("-infinity")) {
return LocalDateTime.MIN;
}
ParsedTimestamp ts = parseBackendTimestamp(s);
// intentionally ignore time zone
// 2004-10-19 10:23:54+03:00 is 2004-10-19 10:23:54 locally
LocalDateTime result = LocalDateTime.of(ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second, ts.nanos);
if (ts.era == GregorianCalendar.BC) {
return result.with(ChronoField.ERA, IsoEra.BCE.getValue());
} else {
return result;
}
}
//JCP! endif
代码示例来源:origin: cn.bestwu.simpleframework/simpleframework-core
/**
* 取得当季度最后一天
*
* @return LocalDateHelper
*/
public LocalDateTimeHelper getLastDayOfQuarter() {
return LocalDateTimeHelper
.of(localDateTime
.withMonth(localDateTime.getMonth().firstMonthOfQuarter().plus(2).getValue())
.with(TemporalAdjusters.lastDayOfMonth())).zoneOffset(zoneOffset);
}
代码示例来源:origin: debezium/debezium
/**
* Get the number of nanoseconds past epoch of the given {@link java.time.LocalDateTime}, {@link java.time.LocalDate},
* {@link java.time.LocalTime}, {@link java.util.Date}, {@link java.sql.Date}, {@link java.sql.Time}, or
* {@link java.sql.Timestamp}.
*
* @param value the local or SQL date, time, or timestamp value; may not be null
* @param adjuster the optional component that adjusts the local date value before obtaining the epoch day; may be null if no
* adjustment is necessary
* @return the epoch nanoseconds
* @throws IllegalArgumentException if the value is not an instance of the acceptable types
*/
public static long toEpochNanos(Object value, TemporalAdjuster adjuster) {
LocalDateTime dateTime = Conversions.toLocalDateTime(value);
if ( adjuster != null) {
dateTime = dateTime.with(adjuster);
}
return Conversions.toEpochNanos(dateTime);
}
代码示例来源:origin: debezium/debezium
/**
* Get the number of microseconds past epoch of the given {@link java.time.LocalDateTime}, {@link java.time.LocalDate},
* {@link java.time.LocalTime}, {@link java.util.Date}, {@link java.sql.Date}, {@link java.sql.Time}, or
* {@link java.sql.Timestamp}.
*
* @param value the local or SQL date, time, or timestamp value; may not be null
* @param adjuster the optional component that adjusts the local date value before obtaining the epoch day; may be null if no
* adjustment is necessary
* @return the epoch microseconds
* @throws IllegalArgumentException if the value is not an instance of the acceptable types
*/
public static long toEpochMicros(Object value, TemporalAdjuster adjuster) {
LocalDateTime dateTime = Conversions.toLocalDateTime(value);
if (adjuster != null) {
dateTime = dateTime.with(adjuster);
}
long epochNanos = Conversions.toEpochNanos(dateTime);
return Math.floorDiv(epochNanos, Conversions.NANOSECONDS_PER_MICROSECOND);
}
代码示例来源:origin: debezium/debezium
/**
* Get the number of milliseconds past epoch of the given {@link java.time.LocalDateTime}, {@link java.time.LocalDate},
* {@link java.time.LocalTime}, {@link java.util.Date}, {@link java.sql.Date}, {@link java.sql.Time}, or
* {@link java.sql.Timestamp}.
*
* @param value the local or SQL date, time, or timestamp value; may not be null
* @param adjuster the optional component that adjusts the local date value before obtaining the epoch day; may be null if no
* adjustment is necessary
* @return the epoch milliseconds
* @throws IllegalArgumentException if the value is not an instance of the acceptable types
*/
public static long toEpochMillis(Object value, TemporalAdjuster adjuster) {
if (value instanceof Long) {
return (Long)value;
}
LocalDateTime dateTime = Conversions.toLocalDateTime(value);
if (adjuster != null) {
dateTime = dateTime.with(adjuster);
}
long epochNanos = Conversions.toEpochNanos(dateTime);
return Math.floorDiv(epochNanos, Conversions.NANOSECONDS_PER_MILLISECOND);
}
代码示例来源:origin: com.thoughtworks.xstream/xstream
return GregorianCalendar.from(LocalDateTime
.from(ta)
.with(WeekFields.ISO.weekOfYear(), y)
.with(WeekFields.ISO.weekOfWeekBasedYear(), w)
.atZone(ZoneId.systemDefault()));
代码示例来源:origin: SeanDragon/protools
/**
* 获取这一年的第一天
*
* @return 天
*/
public DatePlus getFirstDayOfYear() {
return new DatePlus(this.localDateTime.with(TemporalAdjusters.firstDayOfYear()));
}
代码示例来源:origin: SeanDragon/protools
/**
* 获取下个月的第一天
*
* @return 天
*/
public DatePlus getFirstDayOfNextMonth() {
return new DatePlus(this.localDateTime.with(TemporalAdjusters.firstDayOfNextMonth()));
}
代码示例来源:origin: SeanDragon/protools
/**
* 获取这一年的最后一天
*
* @return 天
*/
public DatePlus getLastDayOfYear() {
return new DatePlus(this.localDateTime.with(TemporalAdjusters.lastDayOfYear()));
}
代码示例来源:origin: SeanDragon/protools
/**
* 获取这个月的第一天
*
* @return 天
*/
public DatePlus getFirstDayOfMonth() {
return new DatePlus(this.localDateTime.with(TemporalAdjusters.firstDayOfMonth()));
}
代码示例来源:origin: SeanDragon/protools
/**
* 获取这一年的第一天
*
* @return 天
*/
public DatePlus getFirstDayOfNextYear() {
return new DatePlus(this.localDateTime.with(TemporalAdjusters.firstDayOfNextYear()));
}
代码示例来源:origin: SeanDragon/protools
/**
* 获取这个月的最后一天
*
* @return 天
*/
public DatePlus getLastDayOfMonth() {
return new DatePlus(this.localDateTime.with(TemporalAdjusters.lastDayOfMonth()));
}
代码示例来源:origin: stackoverflow.com
public static void main(String[] args) {
LocalDateTime dateTime = LocalDateTime.now();
LocalDateTime nextMonday = dateTime.with(TemporalAdjusters.next(DayOfWeek.MONDAY));
System.out.println(nextMonday);
}
代码示例来源:origin: dremio/dremio-oss
@Override
public Instant next() {
Instant result = next.atZone(zoneId).toInstant();
next = next.plus(amount).with(adjuster);
return result;
}
代码示例来源:origin: espertechinc/esper
public LocalDateTime evaluate(LocalDateTime ldt, EventBean[] eventsPerStream, boolean isNewData, ExprEvaluatorContext context) {
Integer value = CalendarOpUtil.getInt(valueExpr, eventsPerStream, isNewData, context);
if (value == null) {
return ldt;
}
return ldt.with(fieldName.getChronoField(), value);
}
代码示例来源:origin: com.liumapp.qtools.date/qtools-date
/**
* 获取这一年的第一天
*
* @return 天
*/
public DatePlus getFirstDayOfYear() {
return new DatePlus(this.localDateTime.with(TemporalAdjusters.firstDayOfYear()));
}
代码示例来源:origin: cn.bestwu.simpleframework/simpleframework-core
/**
* 取得当月第一天
*
* @return LocalDateHelper
*/
public LocalDateTimeHelper getFirstDayOfMonth() {
return LocalDateTimeHelper.of(localDateTime.with(TemporalAdjusters.firstDayOfMonth()))
.zoneOffset(zoneOffset);
}
代码示例来源:origin: cn.bestwu.simpleframework/simpleframework-web
/**
* 取得当月最后一天
*
* @return LocalDateHelper
*/
public LocalDateTimeHelper getLastDayOfMonth() {
return LocalDateTimeHelper.of(localDateTime.with(TemporalAdjusters.lastDayOfMonth()))
.zoneOffset(zoneOffset);
}
代码示例来源:origin: espertechinc/esper
public LocalDateTime evaluate(LocalDateTime ldt, EventBean[] eventsPerStream, boolean isNewData, ExprEvaluatorContext context) {
ValueRange range = ldt.range(fieldName.getChronoField());
return ldt.with(fieldName.getChronoField(), range.getMinimum());
}
代码示例来源:origin: kousen/java_8_recipes
@Test
public void adjusters() {
LocalDateTime start = LocalDateTime.of(2017, Month.FEBRUARY, 2, 11, 30);
LocalDateTime end = start.with(TemporalAdjusters.firstDayOfNextMonth());
assertEquals("2017-03-01T11:30", end.toString());
end = start.with(TemporalAdjusters.next(DayOfWeek.THURSDAY));
assertEquals("2017-02-09T11:30", end.toString());
end = start.with(TemporalAdjusters.previousOrSame(DayOfWeek.THURSDAY));
assertEquals("2017-02-02T11:30", end.toString());
}
}
内容来源于网络,如有侵权,请联系作者删除!