本文整理汇总了Java中java.time.LocalDateTime.from方法的典型用法代码示例。如果您正苦于以下问题:Java LocalDateTime.from方法的具体用法?Java LocalDateTime.from怎么用?Java LocalDateTime.from使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.time.LocalDateTime
的用法示例。
在下文中一共展示了LocalDateTime.from方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: includes
import java.time.LocalDateTime; //导入方法依赖的package包/类
private boolean includes(TimeFrame frame, LocalDateTime dateTime) {
LocalDateTime start = LocalDateTime.from(frame.getStart());
LocalDateTime end = LocalDateTime.from(frame.getEnd());
int distance = (int) (ChronoUnit.DAYS.between(start, dateTime) - 1);
if (distance > 0) {
int factor = distance / frame.getRecurrence().getDays();
if (factor > 0) {
Period advance = frame.getRecurrence().multipliedBy(factor);
start.plus(advance);
end.plus(advance);
}
}
while (!start.isAfter(dateTime)) {
if (end.isAfter(dateTime)) {
return true;
}
start = start.plus(frame.getRecurrence());
end = end.plus(frame.getRecurrence());
}
return false;
}
示例2: LocalDateTimeOf
import java.time.LocalDateTime; //导入方法依赖的package包/类
/**
* Parses the date using the formatter to create
* {@link LocalDateTime} instances.
* @param date The date to parse.
* @param formatter The formatter to use.
*/
public LocalDateTimeOf(final CharSequence date,
final DateTimeFormatter formatter) {
this.parsed = new UncheckedScalar<>(
() -> LocalDateTime.from(formatter.parse(date))
);
}
示例3: toMillis
import java.time.LocalDateTime; //导入方法依赖的package包/类
private static long toMillis(String date) {
TemporalAccessor temporalAccessor = DateTimeFormatter.ISO_LOCAL_DATE_TIME.parse(date);
LocalDateTime localDateTime = LocalDateTime.from(temporalAccessor);
ZonedDateTime zonedDateTime = ZonedDateTime.of(localDateTime, ZoneId.systemDefault());
Instant instant = Instant.from(zonedDateTime);
return instant.toEpochMilli();
}
示例4: getLabelBatchHisto
import java.time.LocalDateTime; //导入方法依赖的package包/类
/** Renvoie le label d'historique
* @param batchHisto
* @return
*/
private String getLabelBatchHisto(BatchHisto batchHisto){
String txt = batchHisto.getStateBatchHisto()
+" - "+applicationContext.getMessage("batch.histo.deb", new Object[]{batchHisto.getDateDebBatchHisto().format(formatterDateTime)}, UI.getCurrent().getLocale());
if (batchHisto.getDateFinBatchHisto()!=null){
LocalDateTime dateDeb = LocalDateTime.from(batchHisto.getDateDebBatchHisto());
Long minutes = dateDeb.until(batchHisto.getDateFinBatchHisto(), ChronoUnit.MINUTES);
dateDeb = dateDeb.plusMinutes(minutes);
Long secondes = dateDeb.until(batchHisto.getDateFinBatchHisto(), ChronoUnit.SECONDS);
txt += " - "+applicationContext.getMessage("batch.histo.fin", new Object[]{batchHisto.getDateFinBatchHisto().format(formatterDateTime)}, UI.getCurrent().getLocale());
txt += " - "+applicationContext.getMessage("batch.histo.duree", new Object[]{getTimeFormated(minutes),getTimeFormated(secondes)}, UI.getCurrent().getLocale());
}
return txt;
}
示例5: ofBest
import java.time.LocalDateTime; //导入方法依赖的package包/类
/**
* Obtains an instance from a local date-time using the preferred offset if possible.
*
* @param localDateTime the local date-time, not null
* @param zone the zone identifier, not null
* @param preferredOffset the zone offset, null if no preference
* @return the zoned date-time, not null
*/
static <R extends ChronoLocalDate> ChronoZonedDateTime<R> ofBest(
ChronoLocalDateTimeImpl<R> localDateTime, ZoneId zone, ZoneOffset preferredOffset) {
Objects.requireNonNull(localDateTime, "localDateTime");
Objects.requireNonNull(zone, "zone");
if (zone instanceof ZoneOffset) {
return new ChronoZonedDateTimeImpl<>(localDateTime, (ZoneOffset) zone, zone);
}
ZoneRules rules = zone.getRules();
LocalDateTime isoLDT = LocalDateTime.from(localDateTime);
List<ZoneOffset> validOffsets = rules.getValidOffsets(isoLDT);
ZoneOffset offset;
if (validOffsets.size() == 1) {
offset = validOffsets.get(0);
} else if (validOffsets.size() == 0) {
ZoneOffsetTransition trans = rules.getTransition(isoLDT);
localDateTime = localDateTime.plusSeconds(trans.getDuration().getSeconds());
offset = trans.getOffsetAfter();
} else {
if (preferredOffset != null && validOffsets.contains(preferredOffset)) {
offset = preferredOffset;
} else {
offset = validOffsets.get(0);
}
}
Objects.requireNonNull(offset, "offset"); // protect against bad ZoneRules
return new ChronoZonedDateTimeImpl<>(localDateTime, offset, zone);
}
示例6: ofBest
import java.time.LocalDateTime; //导入方法依赖的package包/类
/**
* Obtains an instance of {@code ZonedDateTime} from a local date-time using the preferred offset if
* possible.
*
* @param localDateTime the local date-time, not null
* @param zoneId the zone identifier, not null
* @param preferredOffset the zone offset, null if no preference
* @return the zoned date-time, not null
*/
static <R extends Chrono<R>> ChronoZonedDateTime<R> ofBest(ChronoDateTimeImpl<R> localDateTime, ZoneId zoneId,
ZoneOffset preferredOffset) {
Jdk7Methods.Objects_requireNonNull(localDateTime, "localDateTime");
Jdk7Methods.Objects_requireNonNull(zoneId, "zoneId");
if (zoneId instanceof ZoneOffset) {
return new ChronoZonedDateTimeImpl<R>(localDateTime, (ZoneOffset) zoneId, zoneId);
}
ZoneRules rules = zoneId.getRules();
LocalDateTime isoLDT = LocalDateTime.from(localDateTime);
List<ZoneOffset> validOffsets = rules.getValidOffsets(isoLDT);
ZoneOffset offset;
if (validOffsets.size() == 1) {
offset = validOffsets.get(0);
} else if (validOffsets.size() == 0) {
// TODO what to do with chrono support in GWT?
// ZoneOffsetTransition trans = rules.getTransition(isoLDT);
// localDateTime = localDateTime.plusSeconds(trans.getDuration().getSeconds());
// offset = trans.getOffsetAfter();
offset = rules.getOffset(isoLDT);
} else {
if (preferredOffset != null && validOffsets.contains(preferredOffset)) {
offset = preferredOffset;
} else {
offset = validOffsets.get(0);
}
}
Jdk7Methods.Objects_requireNonNull(offset, "offset"); // protect against bad ZoneRules
return new ChronoZonedDateTimeImpl<R>(localDateTime, offset, zoneId);
}
示例7: fromJson
import java.time.LocalDateTime; //导入方法依赖的package包/类
@FromJson
LocalDateTime fromJson(String date) {
return LocalDateTime.from(formatter.parse(date));
}
示例8: parseDateTime
import java.time.LocalDateTime; //导入方法依赖的package包/类
public static LocalDateTime parseDateTime(String tsTxt) {
TemporalAccessor tsAccessor = TIMESTAMP_FMT.parse(tsTxt);
return LocalDateTime.from(tsAccessor);
}
示例9: test_from_TemporalAccessor_invalid_noDerive
import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test(expectedExceptions=DateTimeException.class)
public void test_from_TemporalAccessor_invalid_noDerive() {
LocalDateTime.from(LocalTime.of(12, 30));
}
示例10: test_from_TemporalAccessor_null
import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test(expectedExceptions=NullPointerException.class)
public void test_from_TemporalAccessor_null() {
LocalDateTime.from((TemporalAccessor) null);
}
示例11: test_parse_instantNoZone_LDT
import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test(dataProvider = "instantNoZone", expectedExceptions = DateTimeException.class)
public void test_parse_instantNoZone_LDT(DateTimeFormatter formatter, String text, Instant expected) {
TemporalAccessor actual = formatter.parse(text);
LocalDateTime.from(actual);
}
示例12: localDateTime
import java.time.LocalDateTime; //导入方法依赖的package包/类
/**
* Obtains an ISO local date-time from another date-time object.
* <p>
* This is equivalent to {@link LocalDateTime#from(DateTimeAccessor)}.
*
* @param dateTime the date-time object to convert, not null
* @return the ISO local date-time, not null
* @throws DateTimeException if unable to create the date-time
*/
@Override
// override with covariant return type
public LocalDateTime localDateTime(DateTimeAccessor dateTime) {
return LocalDateTime.from(dateTime);
}
示例13: localDateTime
import java.time.LocalDateTime; //导入方法依赖的package包/类
/**
* Obtains an ISO local date-time from another date-time object.
* <p>
* This is equivalent to {@link LocalDateTime#from(TemporalAccessor)}.
*
* @param temporal the date-time object to convert, not null
* @return the ISO local date-time, not null
* @throws DateTimeException if unable to create the date-time
*/
@Override // override with covariant return type
public LocalDateTime localDateTime(TemporalAccessor temporal) {
return LocalDateTime.from(temporal);
}