本文整理了Java中java.time.ZonedDateTime.withDayOfMonth()
方法的一些代码示例,展示了ZonedDateTime.withDayOfMonth()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZonedDateTime.withDayOfMonth()
方法的具体详情如下:
包路径:java.time.ZonedDateTime
类名称:ZonedDateTime
方法名:withDayOfMonth
[英]Returns a copy of this ZonedDateTime with the day-of-month value altered.
This operates on the local time-line, LocalDateTime#withDayOfMonth(int) of the local date-time. This is then converted back to a ZonedDateTime, using the zone ID to obtain the offset.
When converting back to ZonedDateTime, if the local date-time is in an overlap, then the offset will be retained if possible, otherwise the earlier offset will be used. If in a gap, the local date-time will be adjusted forward by the length of the gap.
This instance is immutable and unaffected by this method call.
[中]返回此ZoneDateTime的副本,更改了月日值。
它在本地日期时间的本地时间行LocalDateTime#withDayOfMonth(int)上运行。然后将其转换回ZoneDateTime,使用分区ID获取偏移量。
当转换回ZoneDateTime时,如果本地日期时间重叠,那么如果可能,将保留偏移量,否则将使用较早的偏移量。如果存在间隙,本地日期时间将根据间隙的长度向前调整。
此实例是不可变的,不受此方法调用的影响。
代码示例来源:origin: blynkkk/blynk-server
private ZonedDateTime adjustToStartDate(ZonedDateTime zonedStartAt, ZonedDateTime zonedNow, ZoneId zoneId) {
if (durationType == ReportDurationType.CUSTOM) {
ZonedDateTime zonedStartDate = getZonedFromTs(startTs, zoneId).with(LocalTime.MIN);
if (zonedStartDate.isAfter(zonedNow)) {
zonedStartAt = zonedStartAt
.withDayOfMonth(zonedStartDate.getDayOfMonth())
.withMonth(zonedStartDate.getMonthValue())
.withYear(zonedStartDate.getYear());
}
}
return zonedStartAt;
}
代码示例来源:origin: wildfly/wildfly
case MONTH:
zonedDateTime = zonedDateTime.truncatedTo(ChronoUnit.DAYS)
.withDayOfMonth(1)
.plus(1,ChronoUnit.MONTHS);
break;
代码示例来源:origin: org.elasticsearch/elasticsearch
public ZonedDateTime withDayOfMonth(int value) {
return dt.withDayOfMonth(value);
}
代码示例来源:origin: com.sqlapp/sqlapp-core
/**
* 指定された日付を含む月初を取得します
*
* @param date
* 対象の日付
* @return 年初
*/
public static ZonedDateTime beginningOfMonth(ZonedDateTime date) {
return date.withDayOfMonth(1);
}
代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.elasticsearch
public ZonedDateTime withDayOfMonth(int value) {
return dt.withDayOfMonth(value);
}
代码示例来源:origin: apache/servicemix-bundles
public ZonedDateTime withDayOfMonth(int value) {
return dt.withDayOfMonth(value);
}
代码示例来源:origin: org.elasticsearch/elasticsearch
case 'M':
if (round) {
dateTime = dateTime.withDayOfMonth(1).with(LocalTime.MIN);
} else {
dateTime = dateTime.plusMonths(sign * num);
代码示例来源:origin: com.sqlapp/sqlapp-core
/**
* 指定された日付を含む年初を取得します
*
* @param date
* 対象の日付
* @return 年初
*/
public static ZonedDateTime beginningOfYear(ZonedDateTime date) {
return date.withDayOfMonth(1).withMonth(1);
}
代码示例来源:origin: com.sqlapp/sqlapp-core
/**
* ZonedDateTime型からTime型に変換します
*
* @param dateTime
* @return カレンダー型
*/
private java.sql.Time toTime(final ZonedDateTime dateTime) {
if (dateTime == null) {
return null;
}
java.sql.Time time=new java.sql.Time(dateTime.withZoneSameInstant(AbstractJava8DateConverter.INSTANT_ZONE_ID)
.withYear(1970).withMonth(1).withDayOfMonth(1).toInstant().toEpochMilli());
return time;
}
代码示例来源:origin: com.cronutils/cron-utils
private ZonedDateTime toBeginOfNextMonth(final ZonedDateTime datetime) {
return datetime.truncatedTo(DAYS).plusMonths(1).withDayOfMonth(1);
}
代码示例来源:origin: espertechinc/esper
/**
* NOTE: Code-generation-invoked method, method name and parameter order matters
*
* @param zdt zoneddatetime
* @param year year
* @param month month
* @param day day
* @return ldt
*/
public static ZonedDateTime actionSetYMDZonedDateTime(ZonedDateTime zdt, Integer year, Integer month, Integer day) {
if (year != null) {
zdt = zdt.withYear(year);
}
if (month != null) {
zdt = zdt.withMonth(month);
}
if (day != null) {
zdt = zdt.withDayOfMonth(day);
}
return zdt;
}
代码示例来源:origin: com.guestful.module/guestful.module.jsr310-extensions
@Override
public Instant instant() {
ZonedDateTime dt = ZonedDateTime.now(zone);
if (year != null) dt = dt.withYear(year);
if (month != null) dt = dt.withMonth(month);
if (day != null) dt = dt.withDayOfMonth(day);
if (hour != null) dt = dt.withHour(hour);
if (min != null) dt = dt.withMinute(min);
if (sec != null) dt = dt.withSecond(sec);
return dt.toInstant();
}
代码示例来源:origin: stackoverflow.com
final ScheduledExecutorService executor = /* ... */ ;
Runnable task = new Runnable() {
@Override
public void run() {
ZonedDateTime now = ZonedDateTime.now();
long delay = now.until(now.plusMonths(1), ChronoUnit.MILLIS);
try {
// ...
} finally {
executor.schedule(this, delay, TimeUnit.MILLISECONDS);
}
}
};
int dayOfMonth = 5;
ZonedDateTime dateTime = ZonedDateTime.now();
if (dateTime.getDayOfMonth() >= dayOfMonth) {
dateTime = dateTime.plusMonths(1);
}
dateTime = dateTime.withDayOfMonth(dayOfMonth);
executor.schedule(task,
ZonedDateTime.now().until(dateTime, ChronoUnit.MILLIS),
TimeUnit.MILLISECONDS);
代码示例来源:origin: org.apache.james/apache-james-mailbox-elasticsearch
public static ZonedDateTime computeLowerDate(ZonedDateTime date, SearchQuery.DateResolution resolution) {
switch (resolution) {
case Year:
return date.truncatedTo(ChronoUnit.DAYS).withDayOfYear(1);
case Month:
return date.truncatedTo(ChronoUnit.DAYS).withDayOfMonth(1);
default:
return date.truncatedTo(convertDateResolutionField(resolution));
}
}
代码示例来源:origin: com.cronutils/cron-utils
private ExecutionTimeResult getNextPotentialDayOfMonth(final ZonedDateTime date,
final int lowestHour,
final int lowestMinute,
final int lowestSecond,
final TimeNode node) {
final NearestValue nearestValue = node.getNextValue(date.getDayOfMonth(), 0);
if (nearestValue.getShifts() > 0) {
return new ExecutionTimeResult(date.truncatedTo(DAYS).withDayOfMonth(1).plusMonths(nearestValue.getShifts()), false);
}
return new ExecutionTimeResult(date.truncatedTo(SECONDS).withDayOfMonth(nearestValue.getValue())
.with(LocalTime.of(lowestHour, lowestMinute, lowestSecond)), false);
}
代码示例来源:origin: com.cronutils/cron-utils
private ExecutionTimeResult getNextPotentialMonth(final ZonedDateTime date, final int lowestHour, final int lowestMinute, final int lowestSecond) {
NearestValue nearestValue;
nearestValue = months.getNextValue(date.getMonthValue(), 0);
final int nextMonths = nearestValue.getValue();
if (nearestValue.getShifts() > 0) {
return new ExecutionTimeResult(date.truncatedTo(DAYS).withMonth(1).withDayOfMonth(1).plusYears(nearestValue.getShifts()), false);
}
final Optional<TimeNode> optionalDays = generateDays(cronDefinition,
ZonedDateTime.of(LocalDateTime.of(date.getYear(), nextMonths, 1, 0, 0), date.getZone()));
if (optionalDays.isPresent()) {
final List<Integer> days = optionalDays.get().getValues();
return new ExecutionTimeResult(
date.truncatedTo(SECONDS).withMonth(nextMonths).withDayOfMonth(days.get(0))
.with(LocalTime.of(lowestHour, lowestMinute, lowestSecond)), false);
} else {
return new ExecutionTimeResult(toBeginOfNextMonth(date), false);
}
}
代码示例来源:origin: com.cronutils/cron-utils
private ExecutionTimeResult getPreviousPotentialDayOfMonth(final ZonedDateTime date, final TimeNode days, final int highestHour, final int highestMinute,
final int highestSecond) {
NearestValue nearestValue = days.getPreviousValue(date.getDayOfMonth(), 0);
if (nearestValue.getShifts() > 0) {
ZonedDateTime newDate = ZonedDateTime.of(
LocalDate.of(date.getYear(), date.getMonthValue(), 1),
MAX_SECONDS,
date.getZone()
).minusMonths(nearestValue.getShifts()).with(lastDayOfMonth());
return new ExecutionTimeResult(newDate, false);
}
return new ExecutionTimeResult(date.withDayOfMonth(nearestValue.getValue())
.with(LocalTime.of(highestHour, highestMinute, highestSecond)).truncatedTo(SECONDS), false);
}
代码示例来源:origin: org.wildfly.security/wildfly-elytron
case MONTH:
zonedDateTime = zonedDateTime.truncatedTo(ChronoUnit.DAYS)
.withDayOfMonth(1)
.plus(1,ChronoUnit.MONTHS);
break;
代码示例来源:origin: com.sqlapp/sqlapp-core
/**
* 指定された日付を含む期初を取得します
*
* @param date
* 対象の日付
* @param accountingPeriod
* 決算月
* @return 期初
*/
public static ZonedDateTime beginningOfQuarter(ZonedDateTime date,
int accountingPeriod) {
ZonedDateTime cal = date.withMonth(accountingPeriod);
cal = cal.plusMonths(1);
cal = cal.withDayOfMonth(1);
cal = truncateTime(cal);
if (cal.compareTo(date) == 0) {
return date;
} else if (cal.compareTo(date) < 0) {
cal = cal.plusYears(1);
}
for (int i = 0; i < 8; i++) {
if (cal.compareTo(date) <= 0) {
return cal;
}
cal = cal.plusMonths(-3);
}
return null;
}
代码示例来源:origin: frode-carlsen/cron
break;
nextTime = nextTime.plusMonths(1).withDayOfMonth(1).withHour(0).withMinute(0).withSecond(0).withNano(0);
checkIfDateTimeBarrierIsReached(nextTime, dateTimeBarrier);
内容来源于网络,如有侵权,请联系作者删除!