當前位置: 首頁>>代碼示例>>Java>>正文


Java MutableDateTime.setRounding方法代碼示例

本文整理匯總了Java中org.joda.time.MutableDateTime.setRounding方法的典型用法代碼示例。如果您正苦於以下問題:Java MutableDateTime.setRounding方法的具體用法?Java MutableDateTime.setRounding怎麽用?Java MutableDateTime.setRounding使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.joda.time.MutableDateTime的用法示例。


在下文中一共展示了MutableDateTime.setRounding方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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()));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:24,代碼來源:SimpleJodaTests.java

示例2: truncate

import org.joda.time.MutableDateTime; //導入方法依賴的package包/類
public FDate truncate(final FDateField field) {
    final MutableDateTime delegate = newMutableDateTime();
    delegate.setRounding(field.jodaTimeValue().getField(delegate.getChronology()));
    final FDate truncated = new FDate(delegate);
    return truncated;
}
 
開發者ID:subes,項目名稱:invesdwin-util,代碼行數:7,代碼來源:FDate.java


注:本文中的org.joda.time.MutableDateTime.setRounding方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。