本文整理了Java中java.time.ZonedDateTime.until()
方法的一些代码示例,展示了ZonedDateTime.until()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZonedDateTime.until()
方法的具体详情如下:
包路径:java.time.ZonedDateTime
类名称:ZonedDateTime
方法名:until
[英]Calculates the period between this date-time and another date-time in terms of the specified unit.
This calculates the period between two date-times in terms of a single unit. The start and end points are this and the specified date-time. The result will be negative if the end is before the start. For example, the period in days between two date-times can be calculated using startDateTime.until(endDateTime, DAYS).
The Temporal passed to this method must be a ZonedDateTime. If the time-zone differs between the two zoned date-times, the specified end date-time is normalized to have the same zone as this date-time.
The calculation returns a whole number, representing the number of complete units between the two date-times. For example, the period in months between 2012-06-15T00:00Z and 2012-08-14T23:59Z will only be one month as it is one minute short of two months.
This method operates in association with TemporalUnit#between. The result of this method is a long representing the amount of the specified unit. By contrast, the result of between is an object that can be used directly in addition/subtraction:
long period = start.until(end, MONTHS); // this method
dateTime.plus(MONTHS.between(start, end)); // use in plus/minus
The calculation is implemented in this method for ChronoUnit. The units NANOS, MICROS, MILLIS, SECONDS, MINUTES, HOURS and HALF_DAYS, DAYS, WEEKS, MONTHS, YEARS, DECADES, CENTURIES, MILLENNIA and ERAS are supported. Other ChronoUnit values will throw an exception.
The calculation for date and time units differ.
Date units operate on the local time-line, using the local date-time. For example, the period from noon on day 1 to noon the following day in days will always be counted as exactly one day, irrespective of whether there was a daylight savings change or not.
Time units operate on the instant time-line. The calculation effectively converts both zoned date-times to instants and then calculates the period between the instants. For example, the period from noon on day 1 to noon the following day in hours may be 23, 24 or 25 hours (or some other amount) depending on whether there was a daylight savings change or not.
If the unit is not a ChronoUnit, then the result of this method is obtained by invoking TemporalUnit.between(Temporal, Temporal)passing this as the first argument and the input temporal as the second argument.
This instance is immutable and unaffected by this method call.
[中]根据指定的单位计算此日期时间和另一日期时间之间的时间段。
这将以单个单位计算两个日期时间之间的周期。开始点和结束点是此日期和指定的日期时间。如果结束早于开始,结果将为负值。例如,可以使用startDateTime计算两个日期时间之间的时间段(以天为单位)。直到(endDateTime,天)。
传递给此方法的时间必须是ZonedDateTime。如果两个分区日期时间之间的时区不同,则指定的结束日期时间将标准化为与此日期时间具有相同的时区。
计算返回一个整数,表示两个日期时间之间的完整单位数。例如,2012-06-15T00:00Z和2012-08-14T23:59Z之间的时间段(以月为单位)将仅为一个月,因为它比两个月短一分钟。
该方法与TemporalUnit#between结合使用。此方法的结果是一个长的字符,表示指定单位的数量。相比之下,between的结果是一个可以直接用于加法/减法的对象:
long period = start.until(end, MONTHS); // this method
dateTime.plus(MONTHS.between(start, end)); // use in plus/minus
该计算是在ChronoUnit的这种方法中实现的。支持以纳米、微米、毫秒、秒、分钟、小时和半天、天、周、月、年、几十年、世纪、千年和年代为单位。其他ChronoUnit值将引发异常。
日期和时间单位的计算方法不同。
日期单位在本地时间线上运行,使用本地日期时间。例如,从第1天中午到第二天中午(以天为单位)的时间段将始终精确计算为一天,无论是否有夏时制更改。
时间单位在即时时间线上运行。该计算有效地将两个分区的日期时间转换为瞬间,然后计算两个瞬间之间的时间间隔。例如,从第1天中午到第二天中午的时间(以小时为单位)可能是23、24或25小时(或其他一些时间),这取决于是否有夏时制更改。
如果该单元不是ChronoUnit,则通过调用TemporalUnit获得该方法的结果。(时态,时态)将其作为第一个参数传递,将输入时态作为第二个参数传递。
此实例是不可变的,不受此方法调用的影响。
代码示例来源:origin: chewiebug/GCViewer
/**
* If the next thing in <code>line</code> is a timestamp, it is parsed and returned. If there
* is no timestamp present, the timestamp is calculated
*
* @param line current line
* @param pos current parse positition
* @param datestamp datestamp that may have been parsed
* @return timestamp (either parsed or derived from datestamp)
* @throws ParseException it seemed to be a timestamp but still couldn't be parsed
*/
protected double getTimestamp(final String line, final ParseInformation pos, final ZonedDateTime datestamp)
throws ParseException {
double timestamp = 0;
if (nextIsTimestamp(line, pos)) {
timestamp = parseTimestamp(line, pos);
}
else if (datestamp != null && pos.getFirstDateStamp() != null) {
// if no timestamp was present, calculate difference between last and this date
timestamp = pos.getFirstDateStamp().until(datestamp, ChronoUnit.MILLIS) / (double) 1000;
}
return timestamp;
}
代码示例来源:origin: stackoverflow.com
// java.time
ZonedDateTime startZdt = ZonedDateTime.of( 2015, 06, 30, 23, 59, 00, 00, ZoneOffset.UTC );
ZonedDateTime stopZdt = ZonedDateTime.of( 2015, 07, 01, 00, 01, 00, 00, ZoneOffset.UTC );
long elapsedMillisZdt = startZdt.until( stopZdt, ChronoUnit.MILLIS );
System.out.println( "startZdt: " + startZdt + " stopZdt: " + stopZdt + " = elapsedMillisZdt: " + elapsedMillisZdt );
代码示例来源:origin: stackoverflow.com
ZonedDateTime now = ZonedDateTime.now();
// Do stuff
long seconds = now.until(ZonedDateTime.now(), ChronoUnit.SECONDS);
代码示例来源:origin: com.proofpoint.platform/http-server
@Managed
public Long getDaysUntilCertificateExpiration()
{
return certificateExpiration.map(date -> ZonedDateTime.now().until(date, DAYS))
.orElse(null);
}
代码示例来源:origin: io.airlift/http-server
@Managed
public Long getDaysUntilCertificateExpiration()
{
return certificateExpiration.map(date -> ZonedDateTime.now().until(date, DAYS))
.orElse(null);
}
代码示例来源:origin: com.teradata.airlift/http-server
@Managed
public Long getDaysUntilCertificateExpiration()
{
return certificateExpiration.map(date -> ZonedDateTime.now().until(date, DAYS))
.orElse(null);
}
代码示例来源:origin: com.rbmhtechnology.vind/report-api
public Log(Application application, SuggestionSearch search, SuggestionResult result, ZonedDateTime start, ZonedDateTime end, Session session) {
values = new HashMap<>();
values.put("application", application);
values.put("session", session);
//values.put("module", module);
values.put("timestamp", DateTimeFormatter.ofPattern(SOLR_DATE_TIME_FORMAT).format(start.withZoneSameInstant(ZoneOffset.UTC)));
values.put("type","suggestion");
values.put("request",new SuggestionRequest(search, "suggestion"));
values.put("response",new Response(result.size(), result.getSuggestedFields().size() ,start.until(end, ChronoUnit.MILLIS)));
}
代码示例来源:origin: stackoverflow.com
ZonedDateTime zdt = ZonedDateTime.now(ZoneId.of("US/Eastern"));
ZonedDateTime target2 = zdt
.withHour(15)
.withMinute(0)
.withSecond(0)
.withNano(0);
if (target2.isBefore(zdt)) {
zdt = zdt.plusDays(1);
}
System.out.println(zdt.until(target2, ChronoUnit.MILLIS));
代码示例来源:origin: org.apache.james/james-server-queue-file
long nextDeliveryDelay = ZonedDateTime.now().until(next.get(), ChronoUnit.MILLIS);
scheduler.schedule(() -> {
try {
代码示例来源:origin: com.rbmhtechnology.vind/report-api
public FullTextEntry(Application application, String source, FulltextSearch search, BeanSearchResult result, ZonedDateTime start, ZonedDateTime end, Session session) {
this.application = application;
this.session = session;
this.timeStamp = start;
this.request = new FullTextRequest(search,source);
this.response = new Response(result.getNumOfResults(), start.until(end, ChronoUnit.MILLIS));
this.sorting = search.getSorting().toString();
}
代码示例来源:origin: org.apereo.cas/cas-server-webapp-reports
final ModelAndView modelAndView = new ModelAndView(MONITORING_VIEW_STATISTICS);
modelAndView.addObject("startTime", this.upTimeStartDate);
final double difference = this.upTimeStartDate.until(ZonedDateTime.now(ZoneOffset.UTC), ChronoUnit.MILLIS);
代码示例来源: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: stackoverflow.com
final long millis = zddate.until(zdtime, java.time.temporal.ChronoUnit.MILLIS);
return millis;
代码示例来源:origin: com.rbmhtechnology.vind/report-api
public FullTextEntry(Application application, String source, FulltextSearch search, SearchResult result, ZonedDateTime start, ZonedDateTime end, Session session) {
this.application = application;
this.session = session;
this.timeStamp = start;
this.request = new FullTextRequest(search,source);
this.response = new Response(result.getNumOfResults(), start.until(end, ChronoUnit.MILLIS));
this.sorting = search.getSorting().toString();
this.paging = new Paging(search.getResultSet());
}
代码示例来源:origin: stackoverflow.com
final long millis = zddate.until(zdtime, java.time.temporal.ChronoUnit.MILLIS);
return millis;
代码示例来源:origin: stackoverflow.com
final long millis = zddate.until(zdtime, java.time.temporal.ChronoUnit.MILLIS);
return millis;
代码示例来源:origin: org.eclipse.hawkbit/hawkbit-repository-jpa
final Duration currentIntervalDuration = Duration.of(currentTime.until(timerResetTime, timeUnit), timeUnit)
.dividedBy(eventCount);
代码示例来源:origin: eclipse/hawkbit
final Duration currentIntervalDuration = Duration.of(currentTime.until(timerResetTime, timeUnit), timeUnit)
.dividedBy(eventCount);
内容来源于网络,如有侵权,请联系作者删除!