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


Java DateTimeFormatter.parseMillis方法代碼示例

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


在下文中一共展示了DateTimeFormatter.parseMillis方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testDateRace

import org.joda.time.format.DateTimeFormatter; //導入方法依賴的package包/類
@Test
public void testDateRace() {
  Clock mockClock = mock(Clock.class);
  DateTimeFormatter parser = ISODateTimeFormat.dateTimeParser();
  long two = parser.parseMillis("2013-04-21T02:59:59-00:00");
  long three = parser.parseMillis("2013-04-21T03:00:00-00:00");
  when(mockClock.currentTimeMillis()).thenReturn(two, three);

  // save & modify static state (yuck)
  Clock origClock = BucketPath.getClock();
  BucketPath.setClock(mockClock);

  String pat = "%H:%M";
  String escaped = BucketPath.escapeString(pat,
      new HashMap<String, String>(),
      TimeZone.getTimeZone("UTC"), true, Calendar.MINUTE, 10, true);

  // restore static state
  BucketPath.setClock(origClock);

  Assert.assertEquals("Race condition detected", "02:50", escaped);
}
 
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:23,代碼來源:TestBucketPath.java

示例2: testMultiParsers

import org.joda.time.format.DateTimeFormatter; //導入方法依賴的package包/類
public void testMultiParsers() {
    DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder();
    DateTimeParser[] parsers = new DateTimeParser[3];
    parsers[0] = DateTimeFormat.forPattern("MM/dd/yyyy").withZone(DateTimeZone.UTC).getParser();
    parsers[1] = DateTimeFormat.forPattern("MM-dd-yyyy").withZone(DateTimeZone.UTC).getParser();
    parsers[2] = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss").withZone(DateTimeZone.UTC).getParser();
    builder.append(DateTimeFormat.forPattern("MM/dd/yyyy").withZone(DateTimeZone.UTC).getPrinter(), parsers);

    DateTimeFormatter formatter = builder.toFormatter();

    formatter.parseMillis("2009-11-15 14:12:12");
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:13,代碼來源:SimpleJodaTests.java

示例3: testIsoDateFormatDateOptionalTimeUTC

import org.joda.time.format.DateTimeFormatter; //導入方法依賴的package包/類
public void testIsoDateFormatDateOptionalTimeUTC() {
    DateTimeFormatter formatter = ISODateTimeFormat.dateOptionalTimeParser().withZone(DateTimeZone.UTC);
    long millis = formatter.parseMillis("1970-01-01T00:00:00Z");
    assertThat(millis, equalTo(0L));
    millis = formatter.parseMillis("1970-01-01T00:00:00.001Z");
    assertThat(millis, equalTo(1L));
    millis = formatter.parseMillis("1970-01-01T00:00:00.1Z");
    assertThat(millis, equalTo(100L));
    millis = formatter.parseMillis("1970-01-01T00:00:00.1");
    assertThat(millis, equalTo(100L));
    millis = formatter.parseMillis("1970-01-01T00:00:00");
    assertThat(millis, equalTo(0L));
    millis = formatter.parseMillis("1970-01-01");
    assertThat(millis, equalTo(0L));

    millis = formatter.parseMillis("1970");
    assertThat(millis, equalTo(0L));

    try {
        formatter.parseMillis("1970 kuku");
        fail("formatting should fail");
    } catch (IllegalArgumentException e) {
        // all is well
    }

    // test offset in format
    millis = formatter.parseMillis("1970-01-01T00:00:00-02:00");
    assertThat(millis, equalTo(TimeValue.timeValueHours(2).millis()));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:30,代碼來源:SimpleJodaTests.java

示例4: testIsoVsCustom

import org.joda.time.format.DateTimeFormatter; //導入方法依賴的package包/類
public void testIsoVsCustom() {
    DateTimeFormatter formatter = ISODateTimeFormat.dateOptionalTimeParser().withZone(DateTimeZone.UTC);
    long millis = formatter.parseMillis("1970-01-01T00:00:00");
    assertThat(millis, equalTo(0L));

    formatter = DateTimeFormat.forPattern("yyyy/MM/dd HH:mm:ss").withZone(DateTimeZone.UTC);
    millis = formatter.parseMillis("1970/01/01 00:00:00");
    assertThat(millis, equalTo(0L));

    FormatDateTimeFormatter formatter2 = Joda.forPattern("yyyy/MM/dd HH:mm:ss");
    millis = formatter2.parser().parseMillis("1970/01/01 00:00:00");
    assertThat(millis, equalTo(0L));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:14,代碼來源:SimpleJodaTests.java

示例5: assertDateFormatParsingThrowingException

import org.joda.time.format.DateTimeFormatter; //導入方法依賴的package包/類
private void assertDateFormatParsingThrowingException(String pattern, String invalidDate) {
    try {
        FormatDateTimeFormatter formatter = Joda.forPattern(pattern);
        DateTimeFormatter parser = formatter.parser();
        parser.parseMillis(invalidDate);
        fail(String.format(Locale.ROOT, "Expected parsing exception for pattern [%s] with date [%s], but did not happen", pattern, invalidDate));
    } catch (IllegalArgumentException e) {
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:10,代碼來源:SimpleJodaTests.java

示例6: parseDateTime

import org.joda.time.format.DateTimeFormatter; //導入方法依賴的package包/類
private long parseDateTime(String value, DateTimeZone timeZone) {
    DateTimeFormatter parser = dateTimeFormatter.parser();
    if (timeZone != null) {
        parser = parser.withZone(timeZone);
    }
    try {
        return parser.parseMillis(value);
    } catch (IllegalArgumentException e) {
        
        throw new ElasticsearchParseException("failed to parse date field [{}] with format [{}]", e, value, dateTimeFormatter.format());
    }
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:13,代碼來源:DateMathParser.java

示例7: testIsoDateFormatDateTimeNoMillisUTC

import org.joda.time.format.DateTimeFormatter; //導入方法依賴的package包/類
public void testIsoDateFormatDateTimeNoMillisUTC() {
    DateTimeFormatter formatter = ISODateTimeFormat.dateTimeNoMillis().withZone(DateTimeZone.UTC);
    long millis = formatter.parseMillis("1970-01-01T00:00:00Z");

    assertThat(millis, equalTo(0L));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:7,代碼來源:SimpleJodaTests.java


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