當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。