本文整理了Java中java.time.LocalDateTime.getLong()
方法的一些代码示例,展示了LocalDateTime.getLong()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LocalDateTime.getLong()
方法的具体详情如下:
包路径:java.time.LocalDateTime
类名称:LocalDateTime
方法名:getLong
[英]Gets the value of the specified field from this date-time as a long.
This queries this date-time for the value for the specified field. If it is not possible to return the value, because the field is not supported or for some other reason, an exception is thrown.
If the field is a ChronoField then the query is implemented here. The #isSupported(TemporalField) will return valid values based on this date-time. All other ChronoField instances will throw a DateTimeException.
If the field is not a ChronoField, then the result of this method is obtained by invoking TemporalField.getFrom(TemporalAccessor)passing this as the argument. Whether the value can be obtained, and what the value represents, is determined by the field.
[中]获取指定字段从此日期开始的长时间值。
此操作将在此日期时间查询指定字段的值。如果由于字段不受支持或其他原因而无法返回值,则会引发异常。
如果该字段是一个ChronoField,则在此处实现查询。#isSupported(临时字段)将基于此日期时间返回有效值。所有其他ChronoField实例将引发DateTimeException。
如果字段不是ChronoField,则通过调用TemporalField获得此方法的结果。getFrom(临时Accessor)将此作为参数传递。是否可以获得该值以及该值表示的内容由字段决定。
代码示例来源:origin: olehmberg/winter
@Override
public double calculate(LocalDateTime first, LocalDateTime second) {
if (first == null || second == null) {
return 0.0;
} else {
int diff = Math.abs(Math.toIntExact(first.getLong(ChronoField.EPOCH_DAY)-second.getLong(ChronoField.EPOCH_DAY)));
double norm = Math.min((double) diff / (double) maxDifference, 1.0);
return 1 - norm;
}
}
代码示例来源:origin: dunwu/javacore
public static void main(String[] args) {
LocalDateTime sylvester = LocalDateTime.of(2014, Month.DECEMBER, 31, 23, 59, 59);
DayOfWeek dayOfWeek = sylvester.getDayOfWeek();
System.out.println(dayOfWeek); // WEDNESDAY
Month month = sylvester.getMonth();
System.out.println(month); // DECEMBER
long minuteOfDay = sylvester.getLong(ChronoField.MINUTE_OF_DAY);
System.out.println(minuteOfDay); // 1439
Instant instant = sylvester
.atZone(ZoneId.systemDefault())
.toInstant();
Date legacyDate = Date.from(instant);
System.out.println(legacyDate); // Wed Dec 31 23:59:59 CET 2014
DateTimeFormatter formatter =
DateTimeFormatter
.ofPattern("MMM dd, yyyy - HH:mm");
LocalDateTime parsed = LocalDateTime.parse("Nov 03, 2014 - 07:13", formatter);
String string = parsed.format(formatter);
System.out.println(string); // Nov 03, 2014 - 07:13
}
代码示例来源:origin: com.github.zakgof/tools
@Override
public void write(SimpleOutputStream out, LocalDateTime val) throws IOException {
long epochDay = val.getLong(ChronoField.EPOCH_DAY);
int dayMilli = val.get(ChronoField.MILLI_OF_DAY);
out.write(epochDay);
out.write(dayMilli);
}
代码示例来源:origin: stackoverflow.com
LocalDateTime currentTime = LocalDateTime.now();
LocalDateTime dateResult;
boolean shouldReturnLastMonday = (currentTime.getDayOfWeek() != DayOfWeek.MONDAY) ||
(currentTime.getDayOfWeek() != DayOfWeek.MONDAY && currentTime.getHour() < 2);
if(shouldReturnLastMonday) {
dateResult = currentTime.minus(currentTime.getDayOfWeek().getValue() - DayOfWeek.MONDAY.getValue(), ChronoUnit.DAYS)
.minus(currentTime.getLong(ChronoField.MILLI_OF_DAY), ChronoUnit.MILLIS)
.plus(2, ChronoUnit.HOURS);
} else {
dateResult = currentTime.minus(currentTime.getLong(ChronoField.MILLI_OF_DAY), ChronoUnit.MILLIS)
.plus(2,ChronoUnit.HOURS);
}
代码示例来源:origin: com.github.jcustenborder.netty/netty-codec-syslog
if (result.getLong(ChronoField.YEAR_OF_ERA) == 1) {
result = result.withYear(LocalDateTime.now(this.zoneId).getYear());
代码示例来源:origin: com.github.seratch/java-time-backport
case OFFSET_SECONDS: return getOffset().getTotalSeconds();
return dateTime.getLong(field);
代码示例来源:origin: com.github.seratch/java-time-backport
case OFFSET_SECONDS: return getOffset().getTotalSeconds();
return dateTime.getLong(field);
内容来源于网络,如有侵权,请联系作者删除!