org.joda.time.LocalDate.toDateTime()方法的使用及代码示例

x33g5p2x  于2022-01-23 转载在 其他  
字(13.4k)|赞(0)|评价(0)|浏览(226)

本文整理了Java中org.joda.time.LocalDate.toDateTime()方法的一些代码示例,展示了LocalDate.toDateTime()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LocalDate.toDateTime()方法的具体详情如下:
包路径:org.joda.time.LocalDate
类名称:LocalDate
方法名:toDateTime

LocalDate.toDateTime介绍

[英]Converts this object to a DateTime using a LocalTime to fill in the missing fields and using the default time zone.

The resulting chronology is determined by the chronology of this LocalDate. The chronology of the time must match. If the time is null, the current time in the date's chronology is used.

This method will throw an exception if the datetime that would be created does not exist when the time zone is taken into account.

This instance is immutable and unaffected by this method call.
[中]使用LocalTime填充缺少的字段并使用默认时区将此对象转换为DateTime。
生成的时间顺序由此LocalDate的时间顺序确定。时间顺序必须匹配。如果时间为空,则使用日期年表中的当前时间。
如果考虑时区时,将创建的日期时间不存在,则此方法将引发异常。
此实例是不可变的,不受此方法调用的影响。

代码示例

代码示例来源:origin: joda-time/joda-time

/**
 * Converts this object to a DateTime using a LocalTime to fill in the
 * missing fields and using the default time zone.
 * <p>
 * The resulting chronology is determined by the chronology of this
 * LocalDate. The chronology of the time must match.
 * <p>
 * If the time is null, this method delegates to {@link #toDateTimeAtCurrentTime(DateTimeZone)}
 * and the following documentation does not apply.
 * <p>
 * When the time zone is applied, the local date-time may be affected by daylight saving.
 * In a daylight saving gap, when the local time does not exist,
 * this method will throw an exception.
 * In a daylight saving overlap, when the same local time occurs twice,
 * this method returns the first occurrence of the local time.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param time  the time of day to use, null uses current time
 * @return the DateTime instance
 * @throws IllegalArgumentException if the chronology of the time does not match
 * @throws IllegalInstantException if the local time does not exist when the time zone is applied
 */
public DateTime toDateTime(LocalTime time) {
  return toDateTime(time, null);
}

代码示例来源:origin: JodaOrg/joda-time

/**
 * Converts this object to a DateTime using a LocalTime to fill in the
 * missing fields and using the default time zone.
 * <p>
 * The resulting chronology is determined by the chronology of this
 * LocalDate. The chronology of the time must match.
 * <p>
 * If the time is null, this method delegates to {@link #toDateTimeAtCurrentTime(DateTimeZone)}
 * and the following documentation does not apply.
 * <p>
 * When the time zone is applied, the local date-time may be affected by daylight saving.
 * In a daylight saving gap, when the local time does not exist,
 * this method will throw an exception.
 * In a daylight saving overlap, when the same local time occurs twice,
 * this method returns the first occurrence of the local time.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param time  the time of day to use, null uses current time
 * @return the DateTime instance
 * @throws IllegalArgumentException if the chronology of the time does not match
 * @throws IllegalInstantException if the local time does not exist when the time zone is applied
 */
public DateTime toDateTime(LocalTime time) {
  return toDateTime(time, null);
}

代码示例来源:origin: camunda/camunda-bpm-platform

/**
 * Converts this object to a DateTime using a LocalTime to fill in the
 * missing fields and using the default time zone.
 * <p>
 * The resulting chronology is determined by the chronology of this
 * LocalDate. The chronology of the time must match.
 * If the time is null, the current time in the date's chronology is used.
 * <p>
 * This method will throw an exception if the datetime that would be
 * created does not exist when the time zone is taken into account.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param time  the time of day to use, null means current time
 * @return the DateTime instance
 * @throws IllegalArgumentException if the chronology of the time does not match
 */
public DateTime toDateTime(LocalTime time) {
  return toDateTime(time, null);
}

代码示例来源:origin: killbill/killbill

@Test(groups = "slow")
public void testCreateWithRequestedDate() throws SubscriptionBaseApiException {
  final LocalDate init = clock.getUTCToday();
  final LocalDate requestedDate = init.minusYears(1);
  final String productName = "Shotgun";
  final BillingPeriod term = BillingPeriod.MONTHLY;
  final String planSetName = PriceListSet.DEFAULT_PRICELIST_NAME;
  testListener.pushExpectedEvent(NextEvent.PHASE);
  final DefaultSubscriptionBase subscription = testUtil.createSubscription(bundle, productName, term, planSetName, requestedDate);
  assertNotNull(subscription);
  //
  // In addition to Alignment phase we also test SubscriptionBaseTransition eventIds and created dates.
  // Keep tracks of row events to compare with ids and created dates returned by SubscriptionBaseTransition later.
  //
  final List<SubscriptionBaseEvent> events = subscription.getEvents();
  Assert.assertEquals(events.size(), 2);
  final SubscriptionBaseEvent trialEvent = events.get(0);
  final SubscriptionBaseEvent phaseEvent = events.get(1);
  assertEquals(subscription.getBundleExternalKey(), bundle.getExternalKey());
  assertEquals(subscription.getStartDate().compareTo(requestedDate.toDateTime(accountData.getReferenceTime())), 0);
  assertListenerStatus();
  final SubscriptionBaseTransition transition = subscription.getPreviousTransition();
  assertEquals(transition.getPreviousEventId(), trialEvent.getId());
  assertEquals(transition.getNextEventId(), phaseEvent.getId());
  assertEquals(transition.getPreviousEventCreatedDate().compareTo(trialEvent.getCreatedDate()), 0);
  assertEquals(transition.getNextEventCreatedDate().compareTo(phaseEvent.getCreatedDate()), 0);
}

代码示例来源:origin: killbill/killbill

@Test(groups = "slow")
public void testCancelPlanOnPendingSubscription3() throws SubscriptionBaseApiException {
  final String baseProduct = "Shotgun";
  final BillingPeriod baseTerm = BillingPeriod.MONTHLY;
  final String basePriceList = PriceListSet.DEFAULT_PRICELIST_NAME;
  final LocalDate startDate = clock.getUTCToday().plusDays(5);
  final DefaultSubscriptionBase subscription = testUtil.createSubscription(bundle, baseProduct, baseTerm, basePriceList, startDate);
  assertEquals(subscription.getState(), Entitlement.EntitlementState.PENDING);
  assertEquals(subscription.getStartDate().compareTo(startDate.toDateTime(accountData.getReferenceTime())), 0);
  subscription.cancelWithPolicy(BillingActionPolicy.IMMEDIATE, callContext);
  testListener.pushExpectedEvents(NextEvent.CREATE, NextEvent.CANCEL);
  clock.addDays(5);
  assertListenerStatus();
  final DefaultSubscriptionBase subscription2 = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId(subscription.getId(), internalCallContext);
  assertEquals(subscription2.getStartDate().compareTo(subscription.getStartDate()), 0);
  assertEquals(subscription2.getState(), Entitlement.EntitlementState.CANCELLED);
  assertNull(subscription2.getCurrentPlan());
}

代码示例来源:origin: killbill/killbill

@Test(groups = "slow")
public void testCancelPlanOnPendingSubscription1() throws SubscriptionBaseApiException {
  final String baseProduct = "Shotgun";
  final BillingPeriod baseTerm = BillingPeriod.MONTHLY;
  final String basePriceList = PriceListSet.DEFAULT_PRICELIST_NAME;
  final LocalDate startDate = clock.getUTCToday().plusDays(5);
  final DefaultSubscriptionBase subscription = testUtil.createSubscription(bundle, baseProduct, baseTerm, basePriceList, startDate);
  assertEquals(subscription.getState(), Entitlement.EntitlementState.PENDING);
  assertEquals(subscription.getStartDate().compareTo(startDate.toDateTime(accountData.getReferenceTime())), 0);
  // The code will be smart to infer the cancelation date as being the future startDate
  subscription.cancel(callContext);
  testListener.pushExpectedEvents(NextEvent.CREATE, NextEvent.CANCEL);
  clock.addDays(5);
  assertListenerStatus();
  final DefaultSubscriptionBase subscription2 = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId(subscription.getId(), internalCallContext);
  assertEquals(subscription2.getStartDate().compareTo(subscription.getStartDate()), 0);
  assertEquals(subscription2.getState(), Entitlement.EntitlementState.CANCELLED);
  assertNull(subscription2.getCurrentPlan());
}

代码示例来源:origin: killbill/killbill

@Test(groups = "slow")
public void testCancelPlanOnPendingSubscription2() throws SubscriptionBaseApiException {
  final String baseProduct = "Shotgun";
  final BillingPeriod baseTerm = BillingPeriod.MONTHLY;
  final String basePriceList = PriceListSet.DEFAULT_PRICELIST_NAME;
  final LocalDate startDate = clock.getUTCToday().plusDays(5);
  final DefaultSubscriptionBase subscription = testUtil.createSubscription(bundle, baseProduct, baseTerm, basePriceList, startDate);
  assertEquals(subscription.getState(), Entitlement.EntitlementState.PENDING);
  assertEquals(subscription.getStartDate().compareTo(startDate.toDateTime(accountData.getReferenceTime())), 0);
  try {
    subscription.cancelWithDate(null, callContext);
    fail("Cancel plan should have failed : subscription PENDING");
  } catch (SubscriptionBaseApiException e) {
    assertEquals(e.getCode(), ErrorCode.SUB_INVALID_REQUESTED_DATE.getCode());
  }
  try {
    subscription.cancelWithDate(subscription.getStartDate().minusDays(1), callContext);
    fail("Cancel plan should have failed : subscription PENDING");
  } catch (SubscriptionBaseApiException e) {
    assertEquals(e.getCode(), ErrorCode.SUB_INVALID_REQUESTED_DATE.getCode());
  }
  subscription.cancelWithDate(subscription.getStartDate(), callContext);
  testListener.pushExpectedEvents(NextEvent.CREATE, NextEvent.CANCEL);
  clock.addDays(5);
  assertListenerStatus();
  final DefaultSubscriptionBase subscription2 = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId(subscription.getId(), internalCallContext);
  assertEquals(subscription2.getStartDate().compareTo(subscription.getStartDate()), 0);
  assertEquals(subscription2.getState(), Entitlement.EntitlementState.CANCELLED);
  assertNull(subscription2.getCurrentPlan());
}

代码示例来源:origin: killbill/killbill

assertEquals(subscription.getStartDate().compareTo(startDate.toDateTime(accountData.getReferenceTime())), 0);

代码示例来源:origin: org.motechproject/motech-testing-utils

public MockDateTimeSource(LocalDate localDate) {
  this(localDate.toDateTime(LocalTime.MIDNIGHT));
}

代码示例来源:origin: stackoverflow.com

LocalDate date = new LocalDate();
LocalTime time = LocalTime.MIDNIGHT;
DateTimeZone zone = DateTimeZone.getDefault();
Instant instant = date.toDateTime(time, zone).toInstant();

代码示例来源:origin: org.kuali.kpme/kpme-tk-lm-impl

public void setEndTime(LocalTime endTime) {
  DateTime dateTime = new DateTime(endTimestamp);
  LocalDate localDate = new LocalDate(endTimestamp);
  endTimestamp = new Timestamp(localDate.toDateTime(endTime, dateTime.getZone()).getMillis());
}

代码示例来源:origin: stackoverflow.com

LocalDate localDate = new LocalDate().withMonthOfYear(3).withDayOfMonth(10);
LocalTime localTime = new LocalTime().withHourOfDay(2);
DateTime dateTime = localDate.toDateTime(localTime, DateTimeZone.UTC);
DateTime dt = new DateTime(DateTimeZone.UTC.getMillisKeepLocal(DateTimeZone.getDefault(), dateTime.getMillis()));

System.out.println(dateTime);
System.out.println(dt);

代码示例来源:origin: stackoverflow.com

public static String CalculateUTC_Time(String Date, String Time) {
  String X[] = Time.split(":");

  int Hours = Integer.parseInt(X[0]);
  int Minutes = Integer.parseInt(X[1]);

  LocalDate date = new LocalDate(Date);
  LocalTime time = new LocalTime(Hours, Minutes);
  DateTime dt = date.toDateTime(time);

  SimpleDateFormat f2 = new SimpleDateFormat("HH:mm");
  f2.setTimeZone(TimeZone.getTimeZone("UTC"));
  return (f2.format(dt.toDate()));
}

代码示例来源:origin: com.phloc/phloc-poi

@Nonnull
public Cell addCell (@Nonnull final LocalDate aValue, @Nullable final ExcelStyle aStyle)
{
 return addCell (aValue.toDateTime (CPDT.NULL_LOCAL_TIME), aStyle);
}

代码示例来源:origin: org.kuali.kpme/kpme-tk-lm-impl

public void setBeginTime(LocalTime beginTime) {
  DateTime dateTime = new DateTime(beginTimestamp);
  LocalDate localDate = new LocalDate(beginTimestamp);
  //LocalTime localTime = new LocalTime(beginTime);
  beginTimestamp = new Timestamp(localDate.toDateTime(beginTime, dateTime.getZone()).getMillis());
}

代码示例来源:origin: org.kuali.kpme/kpme-tk-lm-impl

public void setBeginDate(Date beginDate) {
  DateTime dateTime = new DateTime(beginTimestamp);
  LocalDate localDate = new LocalDate(beginDate);
  LocalTime localTime = new LocalTime(beginTimestamp);
  beginTimestamp = new Timestamp(localDate.toDateTime(localTime, dateTime.getZone()).getMillis());
}

代码示例来源:origin: org.kuali.kpme/kpme-tk-lm-impl

public void setEndDate(Date endDate) {
  DateTime dateTime = new DateTime(endTimestamp);
  LocalDate localDate = new LocalDate(endDate);
  LocalTime localTime = new LocalTime(endTimestamp);
  endTimestamp = new Timestamp(localDate.toDateTime(localTime, dateTime.getZone()).getMillis());
}

代码示例来源:origin: org.kuali.kpme/kpme-tk-lm-impl

public void setBeginDate(Date beginDate) {
    DateTime dateTime = new DateTime(beginTimestamp);
    LocalDate localDate = new LocalDate(beginDate);
    LocalTime localTime = new LocalTime(beginTimestamp);
    beginTimestamp = new Timestamp(localDate.toDateTime(localTime, dateTime.getZone()).getMillis());
}

代码示例来源:origin: com.ning.billing/killbill-entitlement

public DateTime fromLocalDateAndReferenceTime(final LocalDate requestedDate, final DateTime referenceDateTime, final DateTimeZone accountTimeZone) {
  final LocalDate localDateNowInAccountTimezone = new LocalDate(requestedDate, accountTimeZone);
  // Datetime from local date in account timezone and with given reference time
  final DateTime t1 = localDateNowInAccountTimezone.toDateTime(referenceDateTime.toLocalTime(), accountTimeZone);
  // Datetime converted back in UTC
  final DateTime t2 = new DateTime(t1, DateTimeZone.UTC);
  //
  // Ok, in the case of a LocalDate of today we expect any change to be immediate, so we check that DateTime returned is not in the future
  // (which means that reference time might not be honored, but this is not very important).
  //
  return adjustDateTimeToNotBeInFutureIfLocaDateIsToday(t2, accountTimeZone);
}

代码示例来源:origin: org.kuali.kpme/kpme-tk-lm-impl

public void setActionDate(Date actionDate) {
  setLocalDate(actionDate != null ? LocalDate.fromDateFields(actionDate) : null);
  //LocalTime localTime = actionDateTime != null ? LocalTime.fromDateFields(actionDateTime) : LocalTime.MIDNIGHT;
  if (localDate != null
      && localTime != null) {
    actionDateTime = localDate.toDateTime(localTime).toDate();
  }
}

相关文章