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

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

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

DateTime.withChronology介绍

[英]Returns a copy of this datetime with a different chronology.

The returned object will be either be a new instance or this. Only the chronology will change, the millis are kept.
[中]返回具有不同年表的此日期时间的副本。
返回的对象将是新实例或this。只有年表会改变,毫秒会保留。

代码示例

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

/**
 * Returns a copy of this datetime with a different time zone, preserving the
 * millisecond instant.
 * <p>
 * This method is useful for finding the local time in another timezone.
 * For example, if this instant holds 12:30 in Europe/London, the result
 * from this method with Europe/Paris would be 13:30.
 * <p>
 * The returned object will be a new instance of the same implementation type.
 * This method changes the time zone, and does not change the
 * millisecond instant, with the effect that the field values usually change.
 * The returned object will be either be a new instance or <code>this</code>.
 *
 * @param newZone  the new time zone
 * @return a copy of this datetime with a different time zone
 * @see #withZoneRetainFields
 */
public DateTime withZone(DateTimeZone newZone) {
  return withChronology(getChronology().withZone(newZone));
}

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

/**
 * Returns a copy of this datetime with a different time zone, preserving the
 * millisecond instant.
 * <p>
 * This method is useful for finding the local time in another timezone.
 * For example, if this instant holds 12:30 in Europe/London, the result
 * from this method with Europe/Paris would be 13:30.
 * <p>
 * The returned object will be a new instance of the same implementation type.
 * This method changes the time zone, and does not change the
 * millisecond instant, with the effect that the field values usually change.
 * The returned object will be either be a new instance or <code>this</code>.
 *
 * @param newZone  the new time zone
 * @return a copy of this datetime with a different time zone
 * @see #withZoneRetainFields
 */
public DateTime withZone(DateTimeZone newZone) {
  return withChronology(getChronology().withZone(newZone));
}

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

/**
 * Returns a copy of this datetime with a different time zone, preserving the
 * millisecond instant.
 * <p>
 * This method is useful for finding the local time in another timezone.
 * For example, if this instant holds 12:30 in Europe/London, the result
 * from this method with Europe/Paris would be 13:30.
 * <p>
 * The returned object will be a new instance of the same implementation type.
 * This method changes the time zone, and does not change the
 * millisecond instant, with the effect that the field values usually change.
 * The returned object will be either be a new instance or <code>this</code>.
 *
 * @param newZone  the new time zone
 * @return a copy of this datetime with a different time zone
 * @see #withZoneRetainFields
 */
public DateTime withZone(DateTimeZone newZone) {
  return withChronology(getChronology().withZone(newZone));
}

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

DateTime dtISO = new DateTime(2014, 1, 9, 0, 0, 0, 0);
DateTimeZone tzSAUDI_ARABIA = DateTimeZone.forID("Asia/Riyadh");
DateTime dtIslamic = 
 dtISO.withChronology(
  IslamicChronology.getInstance(
   tzSAUDI_ARABIA, 
   IslamicChronology.LEAP_YEAR_15_BASED));
System.out.println(dtIslamic);

代码示例来源:origin: dhis2/dhis2-core

@Override
  public DateTimeUnit isoStartOfYear( int year )
  {
    DateTime dateTime = new DateTime( year, 1, 1, 11, 0, chronology ).withChronology( ISOChronology.getInstance() );
    return DateTimeUnit.fromJodaDateTime( dateTime );
  }
}

代码示例来源:origin: org.opensaml/xmltooling

/** {@inheritDoc} */
protected void processElementContent(XMLObject xmlObject, String elementContent) {
  XSDateTime xsDateTime = (XSDateTime) xmlObject;
  
  xsDateTime.setValue(new DateTime(elementContent).withChronology(ISOChronology.getInstanceUTC()));
}

代码示例来源:origin: org.opensaml/opensaml-core

/** {@inheritDoc} */
protected void processElementContent(XMLObject xmlObject, String elementContent) {
  XSDateTime xsDateTime = (XSDateTime) xmlObject;
  
  xsDateTime.setValue(new DateTime(elementContent).withChronology(ISOChronology.getInstanceUTC()));
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.opensaml

/** {@inheritDoc} */
protected void processElementContent(XMLObject xmlObject, String elementContent) {
  XSDateTime xsDateTime = (XSDateTime) xmlObject;
  
  xsDateTime.setValue(new DateTime(elementContent).withChronology(ISOChronology.getInstanceUTC()));
}

代码示例来源:origin: org.opensaml/opensaml-soap-impl

/** {@inheritDoc} */
public void setValue(String newValue) {
  dateTimeValue = new DateTime(newValue).withChronology(ISOChronology.getInstanceUTC());
  stringValue = prepareForAssignment(stringValue, newValue);
}

代码示例来源:origin: org.opensaml/openws

/** {@inheritDoc} */
public void setValue(String newValue) {
  dateTimeValue = new DateTime(newValue).withChronology(ISOChronology.getInstanceUTC());
  stringValue = prepareForAssignment(stringValue, newValue);
}

代码示例来源:origin: io.apigee.opensaml/xmltooling

/** {@inheritDoc} */
protected void processElementContent(XMLObject xmlObject, String elementContent) {
  XSDateTime xsDateTime = (XSDateTime) xmlObject;
  
  xsDateTime.setValue(new DateTime(elementContent).withChronology(ISOChronology.getInstanceUTC()));
}

代码示例来源:origin: org.jruby/jruby-complete

private RubyDate newStart(ThreadContext context, final long start) {
  DateTime dt = this.dt.withChronology(getChronology(context, start, off));
  return newInstance(context, dt, off, start, subMillisNum, subMillisDen);
}

代码示例来源:origin: Unidata/thredds

public static CalendarDate withDoy(Calendar cal, int year, int doy, int hourOfDay, int minuteOfHour, int secondOfMinute) {
 Chronology base = Calendar.getChronology(cal);
 /* if (base == null)
  base = ISOChronology.getInstanceUTC(); // already in UTC
 else
  base = ZonedChronology.getInstance( base, DateTimeZone.UTC); // otherwise wrap it to be in UTC  */
 DateTime dt = new DateTime(year, 1, 1, hourOfDay, minuteOfHour, secondOfMinute, base);
 dt = dt.withZone(DateTimeZone.UTC);
 dt = dt.withDayOfYear(doy);
 if (!Calendar.isDefaultChronology(cal)) dt = dt.withChronology(Calendar.getChronology(cal));
 return new CalendarDate(cal, dt);
}

代码示例来源:origin: dhis2/dhis2-core

@Override
public int isoWeekday( DateTimeUnit dateTimeUnit )
{
  DateTime dateTime = dateTimeUnit.toJodaDateTime( chronology );
  dateTime = dateTime.withChronology( ISOChronology.getInstance( DateTimeZone.getDefault() ) );
  return dateTime.getDayOfWeek();
}

代码示例来源:origin: edu.ucar/netcdf

public static CalendarDate withDoy(Calendar cal, int year, int doy, int hourOfDay, int minuteOfHour, int secondOfMinute) {
 Chronology base = Calendar.getChronology(cal);
 /* if (base == null)
  base = ISOChronology.getInstanceUTC(); // already in UTC
 else
  base = ZonedChronology.getInstance( base, DateTimeZone.UTC); // otherwise wrap it to be in UTC  */
 DateTime dt = new DateTime(year, 1, 1, hourOfDay, minuteOfHour, secondOfMinute, base);
 dt = dt.withZone(DateTimeZone.UTC);
 dt = dt.withDayOfYear(doy);
 if (!Calendar.isDefaultChronology(cal)) dt = dt.withChronology(Calendar.getChronology(cal));
 return new CalendarDate(cal, dt);
}

代码示例来源:origin: edu.ucar/cdm

public static CalendarDate withDoy(Calendar cal, int year, int doy, int hourOfDay, int minuteOfHour, int secondOfMinute) {
 Chronology base = Calendar.getChronology(cal);
 /* if (base == null)
  base = ISOChronology.getInstanceUTC(); // already in UTC
 else
  base = ZonedChronology.getInstance( base, DateTimeZone.UTC); // otherwise wrap it to be in UTC  */
 DateTime dt = new DateTime(year, 1, 1, hourOfDay, minuteOfHour, secondOfMinute, base);
 dt = dt.withZone(DateTimeZone.UTC);
 dt = dt.withDayOfYear(doy);
 if (!Calendar.isDefaultChronology(cal)) dt = dt.withChronology(Calendar.getChronology(cal));
 return new CalendarDate(cal, dt);
}

代码示例来源:origin: org.jruby/jruby-complete

@JRubyMethod(optional = 1, visibility = Visibility.PRIVATE)
public IRubyObject new_offset(ThreadContext context, IRubyObject[] args) {
  IRubyObject of = args.length > 0 ? args[0] : RubyFixnum.zero(context.runtime);
  final int off = val2off(context, of);
  DateTime dt = this.dt.withChronology(getChronology(context, start, off));
  return newInstance(context, dt, off, start);
}

代码示例来源:origin: org.jruby/jruby-core

@JRubyMethod(optional = 1, visibility = Visibility.PRIVATE)
public IRubyObject new_offset(ThreadContext context, IRubyObject[] args) {
  IRubyObject of = args.length > 0 ? args[0] : RubyFixnum.zero(context.runtime);
  final int off = val2off(context, of);
  DateTime dt = this.dt.withChronology(getChronology(context, start, off));
  return newInstance(context, dt, off, start);
}

代码示例来源:origin: dhis2/dhis2-core

@Override
public DateTimeUnit fromIso( DateTimeUnit dateTimeUnit )
{
  if ( !dateTimeUnit.isIso8601() )
  {
    return dateTimeUnit;
  }
  DateTime dateTime = dateTimeUnit.toJodaDateTime( ISOChronology.getInstance( DateTimeZone.forTimeZone( dateTimeUnit.getTimeZone() ) ) );
  dateTime = dateTime.withChronology( chronology );
  return DateTimeUnit.fromJodaDateTime( dateTime );
}

代码示例来源:origin: dhis2/dhis2-core

@Override
public DateTimeUnit toIso( DateTimeUnit dateTimeUnit )
{
  if ( dateTimeUnit.isIso8601() )
  {
    return dateTimeUnit;
  }
  DateTime dateTime = dateTimeUnit.toJodaDateTime( chronology );
  dateTime = dateTime.withChronology( ISOChronology.getInstance( DateTimeZone.forTimeZone( dateTimeUnit.getTimeZone() ) ) );
  return new DateTimeUnit( DateTimeUnit.fromJodaDateTime( dateTime ), true );
}

相关文章

DateTime类方法