org.joda.time.LocalDateTime.<init>()方法的使用及代码示例

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

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

LocalDateTime.<init>介绍

[英]Constructs an instance set to the current local time evaluated using ISO chronology in the default zone.

Once the constructor is completed, the zone is no longer used.
[中]构造一个实例集,该实例集使用默认分区中的ISO年表计算当前本地时间。
一旦构造完成,区域将不再使用。

代码示例

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

/**
 * Obtains a {@code LocalDateTime} set to the current system millisecond time
 * using <code>ISOChronology</code> in the default time zone.
 * The resulting object does not use the zone.
 * 
 * @return the current date, not null
 * @since 2.0
 */
public static LocalDateTime now() {
  return new LocalDateTime();
}

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

/**
 * Obtains a {@code LocalDateTime} set to the current system millisecond time
 * using <code>ISOChronology</code> in the default time zone.
 * The resulting object does not use the zone.
 * 
 * @return the current date, not null
 * @since 2.0
 */
public static LocalDateTime now() {
  return new LocalDateTime();
}

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

/**
 * Obtains a {@code LocalDateTime} set to the current system millisecond time
 * using the specified chronology.
 * The resulting object does not use the zone.
 *
 * @param chronology  the chronology, not null
 * @return the current date, not null
 * @since 2.0
 */
public static LocalDateTime now(Chronology chronology) {
  if (chronology == null) {
    throw new NullPointerException("Chronology must not be null");
  }
  return new LocalDateTime(chronology);
}

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

/**
 * Obtains a {@code LocalDateTime} set to the current system millisecond time
 * using <code>ISOChronology</code> in the specified time zone.
 * The resulting object does not use the zone.
 *
 * @param zone  the time zone, not null
 * @return the current date, not null
 * @since 2.0
 */
public static LocalDateTime now(DateTimeZone zone) {
  if (zone == null) {
    throw new NullPointerException("Zone must not be null");
  }
  return new LocalDateTime(zone);
}

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

/**
 * Obtains a {@code LocalDateTime} set to the current system millisecond time
 * using <code>ISOChronology</code> in the specified time zone.
 * The resulting object does not use the zone.
 *
 * @param zone  the time zone, not null
 * @return the current date, not null
 * @since 2.0
 */
public static LocalDateTime now(DateTimeZone zone) {
  if (zone == null) {
    throw new NullPointerException("Zone must not be null");
  }
  return new LocalDateTime(zone);
}

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

/**
 * Obtains a {@code LocalDateTime} set to the current system millisecond time
 * using the specified chronology.
 * The resulting object does not use the zone.
 *
 * @param chronology  the chronology, not null
 * @return the current date, not null
 * @since 2.0
 */
public static LocalDateTime now(Chronology chronology) {
  if (chronology == null) {
    throw new NullPointerException("Chronology must not be null");
  }
  return new LocalDateTime(chronology);
}

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

/**
 * Converts this object to a <code>LocalDateTime</code> with
 * the same datetime and chronology.
 *
 * @return a LocalDateTime with the same datetime and chronology
 * @since 1.3
 */
public LocalDateTime toLocalDateTime() {
  return new LocalDateTime(getMillis(), getChronology());
}

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

/**
 * Converts this object to a <code>LocalDateTime</code> with
 * the same datetime and chronology.
 *
 * @return a LocalDateTime with the same datetime and chronology
 * @since 1.3
 */
public LocalDateTime toLocalDateTime() {
  return new LocalDateTime(getMillis(), getChronology());
}

代码示例来源:origin: apache/drill

@Override
public java.sql.Timestamp getPrimitiveJavaObject(Object o) {
 final TimeStampHolder h = (TimeStampHolder) o;
 org.joda.time.LocalDateTime dateTime = new org.joda.time.LocalDateTime(h.value, org.joda.time.DateTimeZone.UTC);
 // use "toDate()" to get java.util.Date object with exactly the same fields as this Joda date-time.
 // See more in Javadoc for "LocalDateTime#toDate()"
 return new java.sql.Timestamp(dateTime.toDate().getTime());
}

代码示例来源:origin: apache/drill

@Override
public java.sql.Timestamp getPrimitiveJavaObject(Object o) {
 if (o == null) {
  return null;
 }
 final NullableTimeStampHolder h = (NullableTimeStampHolder) o;
 org.joda.time.LocalDateTime dateTime = new org.joda.time.LocalDateTime(h.value, org.joda.time.DateTimeZone.UTC);
 // use "toDate()" to get java.util.Date object with exactly the same fields as this Joda date-time.
 // See more in Javadoc for "LocalDateTime#toDate()"
 return new java.sql.Timestamp(dateTime.toDate().getTime());
}

代码示例来源:origin: apache/drill

@Override
public TimestampWritable getPrimitiveWritableObject(Object o) {
 if (o == null) {
  return null;
 }
 final NullableTimeStampHolder h = (NullableTimeStampHolder) o;
 org.joda.time.LocalDateTime dateTime = new org.joda.time.LocalDateTime(h.value, org.joda.time.DateTimeZone.UTC);
 // use "toDate()" to get java.util.Date object with exactly the same fields as this Joda date-time.
 // See more in Javadoc for "LocalDateTime#toDate()"
 return new TimestampWritable(new java.sql.Timestamp(dateTime.toDate().getTime()));
}

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

/**
 * Returns a copy of this datetime with different local millis.
 * <p>
 * The returned object will be a new instance of the same type.
 * Only the millis will change, the chronology is kept.
 * The returned object will be either be a new instance or <code>this</code>.
 *
 * @param newMillis  the new millis, from 1970-01-01T00:00:00
 * @return a copy of this datetime with different millis
 */
LocalDateTime withLocalMillis(long newMillis) {
  return (newMillis == getLocalMillis() ? this : new LocalDateTime(newMillis, getChronology()));
}

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

/**
 * Handle broken serialization from other tools.
 * @return the resolved object, not null
 */
private Object readResolve() {
  if (iChronology == null) {
    return new LocalDateTime(iLocalMillis, ISOChronology.getInstanceUTC());
  }
  if (DateTimeZone.UTC.equals(iChronology.getZone()) == false) {
    return new LocalDateTime(iLocalMillis, iChronology.withUTC());
  }
  return this;
}

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

/**
 * Handle broken serialization from other tools.
 * @return the resolved object, not null
 */
private Object readResolve() {
  if (iChronology == null) {
    return new LocalDateTime(iLocalMillis, ISOChronology.getInstanceUTC());
  }
  if (DateTimeZone.UTC.equals(iChronology.getZone()) == false) {
    return new LocalDateTime(iLocalMillis, iChronology.withUTC());
  }
  return this;
}

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

/**
 * Returns a copy of this datetime with different local millis.
 * <p>
 * The returned object will be a new instance of the same type.
 * Only the millis will change, the chronology is kept.
 * The returned object will be either be a new instance or <code>this</code>.
 *
 * @param newMillis  the new millis, from 1970-01-01T00:00:00
 * @return a copy of this datetime with different millis
 */
LocalDateTime withLocalMillis(long newMillis) {
  return (newMillis == getLocalMillis() ? this : new LocalDateTime(newMillis, getChronology()));
}

代码示例来源:origin: apache/incubator-gobblin

private boolean isDatePatternHourly(String datePattern) {
 DateTimeFormatter formatter = DateTimeFormat.forPattern(datePattern);
 LocalDateTime refDateTime = new LocalDateTime(2017, 01, 01, 10, 0, 0);
 String refDateTimeString = refDateTime.toString(formatter);
 LocalDateTime refDateTimeAtStartOfDay = refDateTime.withHourOfDay(0);
 String refDateTimeStringAtStartOfDay = refDateTimeAtStartOfDay.toString(formatter);
 return !refDateTimeString.equals(refDateTimeStringAtStartOfDay);
}

代码示例来源:origin: qunarcorp/qmq

public static long resolveSegment(long offset, int scale) {
  LocalDateTime localDateTime = new LocalDateTime(offset);
  long year = year(localDateTime);
  long month = month(localDateTime);
  long day = day(localDateTime);
  long hour = hour(localDateTime);
  long minute = minute(localDateTime);
  minute = minute - (minute % scale);
  return year + month + day + hour + minute;
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void testBindLocalDateTime() {
  MutablePropertyValues propertyValues = new MutablePropertyValues();
  propertyValues.add("localDateTime", new LocalDateTime(2009, 10, 31, 12, 0));
  binder.bind(propertyValues);
  assertEquals(0, binder.getBindingResult().getErrorCount());
  String value = binder.getBindingResult().getFieldValue("localDateTime").toString();
  assertTrue(value.startsWith("10/31/09"));
  assertTrue(value.endsWith("12:00 PM"));
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void testBindLocalDateTimeAnnotated() {
  MutablePropertyValues propertyValues = new MutablePropertyValues();
  propertyValues.add("localDateTimeAnnotated", new LocalDateTime(2009, 10, 31, 12, 0));
  binder.bind(propertyValues);
  assertEquals(0, binder.getBindingResult().getErrorCount());
  String value = binder.getBindingResult().getFieldValue("localDateTimeAnnotated").toString();
  assertTrue(value.startsWith("Oct 31, 2009"));
  assertTrue(value.endsWith("12:00 PM"));
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void testBindDateTimeWithSpecificStyle() {
  JodaTimeFormatterRegistrar registrar = new JodaTimeFormatterRegistrar();
  registrar.setDateTimeStyle("MM");
  setup(registrar);
  MutablePropertyValues propertyValues = new MutablePropertyValues();
  propertyValues.add("localDateTime", new LocalDateTime(2009, 10, 31, 12, 0));
  binder.bind(propertyValues);
  assertEquals(0, binder.getBindingResult().getErrorCount());
  String value = binder.getBindingResult().getFieldValue("localDateTime").toString();
  assertTrue(value.startsWith("Oct 31, 2009"));
  assertTrue(value.endsWith("12:00:00 PM"));
}

相关文章