当前位置: 首页>>代码示例>>Java>>正文


Java LocalDateTime.from方法代码示例

本文整理汇总了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;
}
 
开发者ID:quanticc,项目名称:sentry,代码行数:22,代码来源:TimeFrameService.java

示例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))
    );
}
 
开发者ID:yegor256,项目名称:cactoos,代码行数:13,代码来源:LocalDateTimeOf.java

示例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();
}
 
开发者ID:DescartesResearch,项目名称:Pet-Supply-Store,代码行数:8,代码来源:TrainingSynchronizer.java

示例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;
}
 
开发者ID:EsupPortail,项目名称:esup-ecandidat,代码行数:18,代码来源:AdminBatchView.java

示例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);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:36,代码来源:ChronoZonedDateTimeImpl.java

示例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);
}
 
开发者ID:kiegroup,项目名称:optashift-employee-rostering,代码行数:40,代码来源:ChronoZonedDateTimeImpl.java

示例7: fromJson

import java.time.LocalDateTime; //导入方法依赖的package包/类
@FromJson
LocalDateTime fromJson(String date) {
    return LocalDateTime.from(formatter.parse(date));
}
 
开发者ID:oneops,项目名称:secrets-cli,代码行数:5,代码来源:DateAdapter.java

示例8: parseDateTime

import java.time.LocalDateTime; //导入方法依赖的package包/类
public static LocalDateTime parseDateTime(String tsTxt) {
    TemporalAccessor tsAccessor = TIMESTAMP_FMT.parse(tsTxt);
    return LocalDateTime.from(tsAccessor);
}
 
开发者ID:cloudwall,项目名称:libcwfincore,代码行数:5,代码来源:GdaxTimestamp.java

示例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));
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:5,代码来源:TCKLocalDateTime.java

示例10: test_from_TemporalAccessor_null

import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test(expectedExceptions=NullPointerException.class)
public void test_from_TemporalAccessor_null() {
    LocalDateTime.from((TemporalAccessor) null);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:5,代码来源:TCKLocalDateTime.java

示例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);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:6,代码来源:TestDateTimeParsing.java

示例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);
}
 
开发者ID:kiegroup,项目名称:optashift-employee-rostering,代码行数:16,代码来源:ISOChrono.java

示例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);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:14,代码来源:IsoChronology.java


注:本文中的java.time.LocalDateTime.from方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。