本文整理了Java中org.joda.time.DateTime.withZoneRetainFields()
方法的一些代码示例,展示了DateTime.withZoneRetainFields()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。DateTime.withZoneRetainFields()
方法的具体详情如下:
包路径:org.joda.time.DateTime
类名称:DateTime
方法名:withZoneRetainFields
[英]Returns a copy of this datetime with a different time zone, preserving the field values.
This method is useful for finding the millisecond time in another timezone. For example, if this instant holds 12:30 in Europe/London (ie. 12:30Z), the result from this method with Europe/Paris would be 12:30 (ie. 11:30Z).
The returned object will be a new instance of the same implementation type. This method changes the time zone and the millisecond instant to keep the field values the same. The returned object will be either be a new instance or this
.
[中]返回具有不同时区的此datetime的副本,保留字段值。
此方法对于在另一时区中查找毫秒时间非常有用。例如,如果该瞬间在欧洲/伦敦(即12:30Z)保持12:30,则该方法在欧洲/巴黎的结果将为12:30(即11:30Z)。
返回的对象将是相同实现类型的新实例。此方法更改时区和毫秒瞬间,以保持字段值相同。返回的对象将是新实例或this
。
代码示例来源:origin: apache/incubator-druid
/**
* The inverse of {@link #jodaToCalciteDate(DateTime, DateTimeZone)}.
*
* @param date Calcite style date
* @param timeZone session time zone
*
* @return joda timestamp, with time zone set to the session time zone
*/
public static DateTime calciteDateToJoda(final int date, final DateTimeZone timeZone)
{
return DateTimes.EPOCH.plusDays(date).withZoneRetainFields(timeZone);
}
代码示例来源:origin: apache/incubator-druid
/**
* The inverse of {@link #jodaToCalciteTimestamp(DateTime, DateTimeZone)}.
*
* @param timestamp Calcite style timestamp
* @param timeZone session time zone
*
* @return joda timestamp, with time zone set to the session time zone
*/
public static DateTime calciteTimestampToJoda(final long timestamp, final DateTimeZone timeZone)
{
return new DateTime(timestamp, DateTimeZone.UTC).withZoneRetainFields(timeZone);
}
代码示例来源:origin: apache/incubator-druid
/**
* Calcite expects "TIMESTAMP" types to be an instant that has the expected local time fields if printed as UTC.
*
* @param dateTime joda timestamp
* @param timeZone session time zone
*
* @return Calcite style millis
*/
public static long jodaToCalciteTimestamp(final DateTime dateTime, final DateTimeZone timeZone)
{
return dateTime.withZone(timeZone).withZoneRetainFields(DateTimeZone.UTC).getMillis();
}
代码示例来源:origin: dlew/joda-time-android
private static long toMillis(ReadableInstant time) {
DateTime dateTime = time instanceof DateTime ? (DateTime) time : new DateTime(time);
DateTime utcDateTime = dateTime.withZoneRetainFields(DateTimeZone.UTC);
return utcDateTime.getMillis();
}
代码示例来源:origin: apache/drill
public TimestampWritable evaluate(TimestampWritable t) {
if (t == null) {
return null;
}
final long originalTimestamp = t.getTimestamp().getTime(); // default
final long originalTimestampUTC = new DateTime(originalTimestamp)
.withZoneRetainFields(DateTimeZone.UTC).getMillis(); // default -> utc
final long newTimestampUTC = granularity.truncate(originalTimestampUTC); // utc
final long newTimestamp = new DateTime(newTimestampUTC, DateTimeZone.UTC)
.withZoneRetainFields(DateTimeZone.getDefault()).getMillis(); // utc -> default
result.setTime(newTimestamp);
return result;
}
代码示例来源:origin: apache/incubator-druid
@JsonCreator
public PeriodGranularity(
@JsonProperty("period") Period period,
@JsonProperty("origin") DateTime origin,
@JsonProperty("timeZone") DateTimeZone tz
)
{
this.period = Preconditions.checkNotNull(period, "period can't be null!");
Preconditions.checkArgument(!Period.ZERO.equals(period), "zero period is not acceptable in QueryGranularity!");
this.chronology = tz == null ? ISOChronology.getInstanceUTC() : ISOChronology.getInstance(tz);
if (origin == null) {
// default to origin in given time zone when aligning multi-period granularities
this.origin = new DateTime(0, DateTimeZone.UTC).withZoneRetainFields(chronology.getZone()).getMillis();
this.hasOrigin = false;
} else {
this.origin = origin.getMillis();
this.hasOrigin = true;
}
this.isCompound = isCompoundPeriod(period);
}
代码示例来源:origin: apache/drill
@Override
public void setSafeValue(ObjectInspector oi, Object hiveFieldValue, ValueVector outputVV, int outputIndex) {
final java.sql.Timestamp value = ((TimestampObjectInspector)oi).getPrimitiveJavaObject(hiveFieldValue);
final DateTime ts = new DateTime(value.getTime()).withZoneRetainFields(DateTimeZone.UTC);
((NullableTimeStampVector) outputVV).getMutator().setSafe(outputIndex, ts.getMillis());
}
}
代码示例来源:origin: apache/drill
@Override
public void setSafeValue(ObjectInspector oi, Object hiveFieldValue, ValueVector outputVV, int outputIndex) {
final java.sql.Date value = ((DateObjectInspector)oi).getPrimitiveJavaObject(hiveFieldValue);
final DateTime date = new DateTime(value.getTime()).withZoneRetainFields(DateTimeZone.UTC);
((NullableDateVector) outputVV).getMutator().setSafe(outputIndex, date.getMillis());
}
}
代码示例来源:origin: apache/hive
public PeriodGranularity(Period period, DateTime origin, DateTimeZone tz) {
this.period = period;
this.chronology = tz == null ? ISOChronology.getInstanceUTC() : ISOChronology.getInstance(tz);
if (origin == null) {
// default to origin in given time zone when aligning multi-period granularities
this.origin = new DateTime(0, DateTimeZone.UTC).withZoneRetainFields(chronology.getZone())
.getMillis();
this.hasOrigin = false;
} else {
this.origin = origin.getMillis();
this.hasOrigin = true;
}
this.isCompound = isCompoundPeriod(period);
}
代码示例来源:origin: apache/drill
public PeriodGranularity(Period period, DateTime origin, DateTimeZone tz) {
this.period = period;
this.chronology = tz == null ? ISOChronology.getInstanceUTC() : ISOChronology.getInstance(tz);
if (origin == null) {
// default to origin in given time zone when aligning multi-period granularities
this.origin = new DateTime(0, DateTimeZone.UTC).withZoneRetainFields(chronology.getZone())
.getMillis();
this.hasOrigin = false;
} else {
this.origin = origin.getMillis();
this.hasOrigin = true;
}
this.isCompound = isCompoundPeriod(period);
}
代码示例来源:origin: apache/incubator-druid
/**
* Calcite expects "DATE" types to be number of days from the epoch to the UTC date matching the local time fields.
*
* @param dateTime joda timestamp
* @param timeZone session time zone
*
* @return Calcite style date
*/
public static int jodaToCalciteDate(final DateTime dateTime, final DateTimeZone timeZone)
{
final DateTime date = dateTime.withZone(timeZone).dayOfMonth().roundFloorCopy();
return Days.daysBetween(DateTimes.EPOCH, date.withZoneRetainFields(DateTimeZone.UTC)).getDays();
}
代码示例来源:origin: apache/drill
private DateTime parseDateFromPostgres(String date, String pattern) {
String jodaFormat = toJodaFormat(pattern);
DateTimeFormatter format = forPattern(jodaFormat).withLocale(Locale.US);
return parse(date, format).withZoneRetainFields(DateTimeZone.UTC);
}
}
代码示例来源:origin: apache/incubator-druid
/**
* Translates "literal" (a TIMESTAMP or DATE literal) to milliseconds since the epoch using the provided
* session time zone.
*
* @param literal TIMESTAMP or DATE literal
* @param timeZone session time zone
*
* @return milliseconds time
*/
public static DateTime calciteDateTimeLiteralToJoda(final RexNode literal, final DateTimeZone timeZone)
{
final SqlTypeName typeName = literal.getType().getSqlTypeName();
if (literal.getKind() != SqlKind.LITERAL || (typeName != SqlTypeName.TIMESTAMP && typeName != SqlTypeName.DATE)) {
throw new IAE("Expected literal but got[%s]", literal.getKind());
}
if (typeName == SqlTypeName.TIMESTAMP) {
final TimestampString timestampString = (TimestampString) RexLiteral.value(literal);
return CALCITE_TIMESTAMP_PARSER.parse(timestampString.toString()).withZoneRetainFields(timeZone);
} else if (typeName == SqlTypeName.DATE) {
final DateString dateString = (DateString) RexLiteral.value(literal);
return CALCITE_DATE_PARSER.parse(dateString.toString()).withZoneRetainFields(timeZone);
} else {
throw new IAE("Expected TIMESTAMP or DATE but got[%s]", typeName);
}
}
代码示例来源:origin: apache/drill
DateTime ts = new DateTime(((Timestamp) val).getTime()).withZoneRetainFields(DateTimeZone.UTC);
long value = ts.getMillis();
for (int i = start; i < end; i++) {
DateTime date = new DateTime(((Date)val).getTime()).withZoneRetainFields(DateTimeZone.UTC);
long value = date.getMillis();
for (int i = start; i < end; i++) {
代码示例来源:origin: org.apache.drill.exec/drill-java-exec
public void eval() {
long inputMillis = 0;
inputMillis = (long) (left.value * 1000L);
out.value = new org.joda.time.DateTime(inputMillis).withZoneRetainFields(org.joda.time.DateTimeZone.UTC).getMillis();
}
}
代码示例来源:origin: org.apache.drill.exec/drill-java-exec
public void eval() {
long inputMillis = 0;
inputMillis = (long) (left.value * 1000L);
out.value = new org.joda.time.DateTime(inputMillis).withZoneRetainFields(org.joda.time.DateTimeZone.UTC).getMillis();
}
}
代码示例来源:origin: org.apache.drill.exec/drill-java-exec
public void eval() {
// Get the input
byte[] buf1 = new byte[left.end - left.start];
left.buffer.getBytes(left.start, buf1, 0, left.end - left.start);
String input = new String(buf1, com.google.common.base.Charsets.UTF_8);
out.value = org.joda.time.DateTime.parse(input, format).withZoneRetainFields(org.joda.time.DateTimeZone.UTC).getMillis();
}
}
代码示例来源:origin: org.jadira.usertype/usertype.core
@Override
public DateTime fromNonNullValue(String s) {
DateTime parsedDateTime = DATE_TIME_PARSER.parseDateTime(s);
DateTimeZone correctTimeZone = parsedDateTime.getZone();
DateTime utcDateTime = parsedDateTime.withZoneRetainFields(DateTimeZone.UTC);
DateTime correctedDateTime = utcDateTime.withZone(correctTimeZone);
return correctedDateTime;
}
代码示例来源:origin: com.google.api-ads/ads-lib
/**
* Converts a string in the form of {@code yyyy-MM-dd'T'HH:mm:ss} to an API
* date time in the time zone supplied.
*/
public T toDateTime(String dateTime, String timeZoneId) {
return toDateTime(ISODateTimeFormat.dateHourMinuteSecond().parseDateTime(dateTime)
.withZoneRetainFields(DateTimeZone.forTimeZone(TimeZone.getTimeZone(timeZoneId))));
}
代码示例来源:origin: org.apache.drill.exec/drill-java-exec
private void writeDateTime(long readDateTime, final MapOrListWriterImpl writer, String fieldName, boolean isList) {
DateTime date = new DateTime(readDateTime);
TimeStampWriter dt;
if (isList == false) {
dt = writer.map.timeStamp(fieldName);
} else {
dt = writer.list.timeStamp();
}
dt.writeTimeStamp(date.withZoneRetainFields(org.joda.time.DateTimeZone.UTC).getMillis());
}
内容来源于网络,如有侵权,请联系作者删除!