当前位置: 首页>>代码示例>>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;未经允许,请勿转载。