本文整理匯總了Java中org.joda.time.MutableDateTime.setZone方法的典型用法代碼示例。如果您正苦於以下問題:Java MutableDateTime.setZone方法的具體用法?Java MutableDateTime.setZone怎麽用?Java MutableDateTime.setZone使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.joda.time.MutableDateTime
的用法示例。
在下文中一共展示了MutableDateTime.setZone方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testRoundingWithTimeZone
import org.joda.time.MutableDateTime; //導入方法依賴的package包/類
public void testRoundingWithTimeZone() {
MutableDateTime time = new MutableDateTime(DateTimeZone.UTC);
time.setZone(DateTimeZone.forOffsetHours(-2));
time.setRounding(time.getChronology().dayOfMonth(), MutableDateTime.ROUND_FLOOR);
MutableDateTime utcTime = new MutableDateTime(DateTimeZone.UTC);
utcTime.setRounding(utcTime.getChronology().dayOfMonth(), MutableDateTime.ROUND_FLOOR);
time.setMillis(utcTimeInMillis("2009-02-03T01:01:01"));
utcTime.setMillis(utcTimeInMillis("2009-02-03T01:01:01"));
assertThat(time.toString(), equalTo("2009-02-02T00:00:00.000-02:00"));
assertThat(utcTime.toString(), equalTo("2009-02-03T00:00:00.000Z"));
// the time is on the 2nd, and utcTime is on the 3rd, but, because time already encapsulates
// time zone, the millis diff is not 24, but 22 hours
assertThat(time.getMillis(), equalTo(utcTime.getMillis() - TimeValue.timeValueHours(22).millis()));
time.setMillis(utcTimeInMillis("2009-02-04T01:01:01"));
utcTime.setMillis(utcTimeInMillis("2009-02-04T01:01:01"));
assertThat(time.toString(), equalTo("2009-02-03T00:00:00.000-02:00"));
assertThat(utcTime.toString(), equalTo("2009-02-04T00:00:00.000Z"));
assertThat(time.getMillis(), equalTo(utcTime.getMillis() - TimeValue.timeValueHours(22).millis()));
}
示例2: doEvaluate
import org.joda.time.MutableDateTime; //導入方法依賴的package包/類
@Override
protected void doEvaluate(TExecutionContext context, LazyList<? extends ValueSource> inputs, ValueTarget output)
{
long original = inputs.get(0).getInt64();
long[] ymd = MDateAndTime.decodeDateTime(original);
if(!MDateAndTime.isValidDateTime(ymd, ZeroFlag.YEAR)) {
output.putNull();
} else {
try {
DateTimeZone fromTz = MDateAndTime.parseTimeZone(inputs.get(1).getString());
DateTimeZone toTz = MDateAndTime.parseTimeZone(inputs.get(2).getString());
MutableDateTime date = MDateAndTime.toJodaDateTime(ymd, fromTz);
// If the value falls out of the supported range of the TIMESTAMP
// when converted from fromTz to UTC, no conversion occurs.
date.setZone(DateTimeZone.UTC);
final long converted;
if(MDateAndTime.isValidTimestamp(date)) {
date.setZone(toTz);
converted = MDateAndTime.encodeDateTime(date);
} else {
converted = original;
}
output.putInt64(converted);
} catch(InvalidDateFormatException e) {
context.warnClient(e);
output.putNull();
}
}
}
示例3: parseMutableDateTime
import org.joda.time.MutableDateTime; //導入方法依賴的package包/類
/**
* Parses a date-time from the given text, returning a new MutableDateTime.
* <p>
* The parse will use the zone and chronology specified on this formatter.
* <p>
* If the text contains a time zone string then that will be taken into
* account in adjusting the time of day as follows.
* If the {@link #withOffsetParsed()} has been called, then the resulting
* DateTime will have a fixed offset based on the parsed time zone.
* Otherwise the resulting DateTime will have the zone of this formatter,
* but the parsed zone may have caused the time to be adjusted.
*
* @param text the text to parse, not null
* @return the parsed date-time, never null
* @throws UnsupportedOperationException if parsing is not supported
* @throws IllegalArgumentException if the text to parse is invalid
*/
public MutableDateTime parseMutableDateTime(String text) {
DateTimeParser parser = requireParser();
Chronology chrono = selectChronology(null);
DateTimeParserBucket bucket = new DateTimeParserBucket(0, chrono, iLocale, iPivotYear, iDefaultYear);
int newPos = parser.parseInto(bucket, text, 0);
if (newPos >= 0) {
if (newPos >= text.length()) {
long millis = bucket.computeMillis(true, text);
if (iOffsetParsed && bucket.getOffsetInteger() != null) {
int parsedOffset = bucket.getOffsetInteger();
DateTimeZone parsedZone = DateTimeZone.forOffsetMillis(parsedOffset);
chrono = chrono.withZone(parsedZone);
} else if (bucket.getZone() != null) {
chrono = chrono.withZone(bucket.getZone());
}
MutableDateTime dt = new MutableDateTime(millis, chrono);
if (iZone != null) {
dt.setZone(iZone);
}
return dt;
}
} else {
newPos = ~newPos;
}
throw new IllegalArgumentException(FormatUtils.createErrorMessage(text, newPos));
}