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

x33g5p2x  于2022-01-17 转载在 其他  
字(8.3k)|赞(0)|评价(0)|浏览(473)

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

DateTime.getMillis介绍

暂无

代码示例

代码示例来源:origin: prestodb/presto

private DateTime toDateTime(long instantNanos)
  {
    long millisSinceCreate = NANOSECONDS.toMillis(instantNanos - createNanos);
    return new DateTime(createTime.getMillis() + millisSinceCreate);
  }
}

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

/**
 * Returns a copy of this datetime with different millis.
 * <p>
 * The returned object will be either be a new instance or <code>this</code>.
 * Only the millis will change, the chronology and time zone are kept.
 *
 * @param newMillis  the new millis, from 1970-01-01T00:00:00Z
 * @return a copy of this datetime with different millis
 */
public DateTime withMillis(long newMillis) {
  return (newMillis == getMillis() ? this : new DateTime(newMillis, getChronology()));
}

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

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

代码示例来源:origin: prestodb/presto

@Test
public void testDate()
    throws Exception
{
  Date expected = new Date(new DateTime(2001, 2, 3, 4, 5, 6, DateTimeZone.UTC).getMillis());
  AccumuloRowSerializer serializer = serializerClass.getConstructor().newInstance();
  byte[] data = serializer.encode(DATE, expected);
  deserializeData(serializer, data);
  Date actual = serializer.getDate(COLUMN_NAME);
  // Convert milliseconds to days so they can be compared regardless of the time of day
  assertEquals(MILLISECONDS.toDays(actual.getTime()), MILLISECONDS.toDays(expected.getTime()));
}

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

/**
 * Returns a copy of this datetime with the year of era field updated.
 * <p>
 * DateTime is immutable, so there are no set methods.
 * Instead, this method returns a new instance with the value of
 * year of era changed.
 *
 * @param yearOfEra  the year of era to set
 * @return a copy of this object with the field set
 * @throws IllegalArgumentException if the value is invalid
 * @since 1.3
 */
public DateTime withYearOfEra(int yearOfEra) {
  return withMillis(getChronology().yearOfEra().set(getMillis(), yearOfEra));
}

代码示例来源:origin: prestodb/presto

@Test
public void testToUnixTime()
{
  assertFunction("to_unixtime(" + TIMESTAMP_LITERAL + ")", DOUBLE, TIMESTAMP.getMillis() / 1000.0);
  assertFunction("to_unixtime(" + WEIRD_TIMESTAMP_LITERAL + ")", DOUBLE, WEIRD_TIMESTAMP.getMillis() / 1000.0);
}

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

/**
 * Rounds to the nearest whole unit of this field on a copy of this DateTime,
 * favoring the ceiling if halfway.
 *
 * @return a copy of the DateTime with the field value changed
 */
public DateTime roundHalfCeilingCopy() {
  return iInstant.withMillis(iField.roundHalfCeiling(iInstant.getMillis()));
}

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

/**
 * Sets this field in a copy of the DateTime.
 * <p>
 * The DateTime attached to this property is unchanged by this call.
 * This operation is faster than converting a DateTime to a MutableDateTime
 * and back again when setting one field. When setting multiple fields,
 * it is generally quicker to make the conversion to MutableDateTime.
 * 
 * @param value  the value to set the field in the copy to
 * @return a copy of the DateTime with the field value changed
 * @throws IllegalArgumentException if the value isn't valid
 */
public DateTime setCopy(int value) {
  return iInstant.withMillis(iField.set(iInstant.getMillis(), value));
}

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

/**
 * Returns a copy of this datetime with the specified duration added.
 * <p>
 * If the addition is zero, then <code>this</code> is returned.
 * 
 * @param durationToAdd  the duration to add to this one
 * @param scalar  the amount of times to add, such as -1 to subtract once
 * @return a copy of this datetime with the duration added
 * @throws ArithmeticException if the new datetime exceeds the capacity of a long
 */
public DateTime withDurationAdded(long durationToAdd, int scalar) {
  if (durationToAdd == 0 || scalar == 0) {
    return this;
  }
  long instant = getChronology().add(getMillis(), durationToAdd, scalar);
  return withMillis(instant);
}

代码示例来源:origin: prestodb/presto

@Test
public void testCastToDate()
{
  long millis = new DateTime(2001, 1, 22, 0, 0, UTC).getMillis();
  assertFunction("cast(TIMESTAMP '2001-1-22 03:04:05.321 +07:09' as date)", DATE, new SqlDate((int) TimeUnit.MILLISECONDS.toDays(millis)));
}

代码示例来源:origin: prestodb/presto

public TimestampStreamReader(StreamDescriptor streamDescriptor, DateTimeZone hiveStorageTimeZone, LocalMemoryContext systemMemoryContext)
{
  this.streamDescriptor = requireNonNull(streamDescriptor, "stream is null");
  this.baseTimestampInSeconds = new DateTime(2015, 1, 1, 0, 0, requireNonNull(hiveStorageTimeZone, "hiveStorageTimeZone is null")).getMillis() / MILLIS_PER_SECOND;
  this.systemMemoryContext = requireNonNull(systemMemoryContext, "systemMemoryContext is null");
}

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

/**
 * Returns a copy of this datetime with the year field updated.
 * <p>
 * DateTime is immutable, so there are no set methods.
 * Instead, this method returns a new instance with the value of
 * year changed.
 *
 * @param year  the year to set
 * @return a copy of this object with the field set
 * @throws IllegalArgumentException if the value is invalid
 * @since 1.3
 */
public DateTime withYear(int year) {
  return withMillis(getChronology().year().set(getMillis(), year));
}

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

/**
 * Returns a copy of this datetime with different millis.
 * <p>
 * The returned object will be either be a new instance or <code>this</code>.
 * Only the millis will change, the chronology and time zone are kept.
 *
 * @param newMillis  the new millis, from 1970-01-01T00:00:00Z
 * @return a copy of this datetime with different millis
 */
public DateTime withMillis(long newMillis) {
  return (newMillis == getMillis() ? this : new DateTime(newMillis, getChronology()));
}

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

/**
 * Converts this object to a <code>TimeOfDay</code> using the
 * same millis and chronology.
 * 
 * @return a TimeOfDay using the same millis and chronology
 * @deprecated Use LocalTime instead of TimeOfDay
 */
@Deprecated
public TimeOfDay toTimeOfDay() {
  return new TimeOfDay(getMillis(), getChronology());
}

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

/**
 * Rounds to the lowest whole unit of this field on a copy of this DateTime.
 *
 * @return a copy of the DateTime with the field value changed
 */
public DateTime roundFloorCopy() {
  return iInstant.withMillis(iField.roundFloor(iInstant.getMillis()));
}

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

/**
 * Sets this field in a copy of the DateTime to a parsed text value.
 * <p>
 * The DateTime attached to this property is unchanged by this call.
 * This operation is faster than converting a DateTime to a MutableDateTime
 * and back again when setting one field. When setting multiple fields,
 * it is generally quicker to make the conversion to MutableDateTime.
 * 
 * @param text  the text value to set
 * @param locale  optional locale to use for selecting a text symbol
 * @return a copy of the DateTime with the field value changed
 * @throws IllegalArgumentException if the text value isn't valid
 */
public DateTime setCopy(String text, Locale locale) {
  return iInstant.withMillis(iField.set(iInstant.getMillis(), text, locale));
}

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

/**
 * Returns a copy of this datetime with the partial set of fields replacing those
 * from this instance.
 * <p>
 * For example, if the partial is a <code>TimeOfDay</code> then the time fields
 * would be changed in the returned instance.
 * If the partial is null, then <code>this</code> is returned.
 *
 * @param partial  the partial set of fields to apply to this datetime, null ignored
 * @return a copy of this datetime with a different set of fields
 * @throws IllegalArgumentException if any value is invalid
 */
public DateTime withFields(ReadablePartial partial) {
  if (partial == null) {
    return this;
  }
  return withMillis(getChronology().set(partial, getMillis()));
}

代码示例来源:origin: prestodb/presto

@Test
public void testCastToTimestampWithTimeZone()
{
  assertFunction("cast(TIME '03:04:05.321 +07:09' as timestamp with time zone)",
      TIMESTAMP_WITH_TIME_ZONE,
      new SqlTimestampWithTimeZone(new DateTime(1970, 1, 1, 3, 4, 5, 321, WEIRD_ZONE).getMillis(), WEIRD_TIME_ZONE_KEY));
}

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

@Override
public DateTime bucketStart(DateTime time)
{
 return new DateTime(truncate(time.getMillis()), getTimeZone());
}

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

/**
 * Returns a copy of this datetime with the month of year field updated.
 * <p>
 * DateTime is immutable, so there are no set methods.
 * Instead, this method returns a new instance with the value of
 * month of year changed.
 *
 * @param monthOfYear  the month of year to set
 * @return a copy of this object with the field set
 * @throws IllegalArgumentException if the value is invalid
 * @since 1.3
 */
public DateTime withMonthOfYear(int monthOfYear) {
  return withMillis(getChronology().monthOfYear().set(getMillis(), monthOfYear));
}

相关文章

DateTime类方法