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


Java DateTimeFormatter.parseLocalDateTime方法代碼示例

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


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

示例1: testUnixTimeStampForDateWithPattern

import org.joda.time.format.DateTimeFormatter; //導入方法依賴的package包/類
@Test
public void testUnixTimeStampForDateWithPattern() throws Exception {
  DateTimeFormatter formatter = DateFunctionsUtils.getFormatterForFormatString("YYYY-MM-DD HH:MI:SS.FFF");
  date = formatter.parseLocalDateTime("2009-03-20 11:30:01.0");
  unixTimeStamp = com.dremio.common.util.DateTimes.toMillis(date) / 1000;

  testBuilder()
      .sqlQuery("select unix_timestamp('2009-03-20 11:30:01.0', 'YYYY-MM-DD HH:MI:SS.FFF') from cp.`employee.json` limit 1")
      .ordered()
      .baselineColumns("EXPR$0")
      .baselineValues(unixTimeStamp)
      .build().run();

  formatter = DateFunctionsUtils.getFormatterForFormatString("YYYY-MM-DD");
  date = formatter.parseLocalDateTime("2009-03-20");
  unixTimeStamp = com.dremio.common.util.DateTimes.toMillis(date) / 1000;

  testBuilder()
      .sqlQuery("select unix_timestamp('2009-03-20', 'YYYY-MM-DD') from cp.`employee.json` limit 1")
      .ordered()
      .baselineColumns("EXPR$0")
      .baselineValues(unixTimeStamp)
      .build().run();
}
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:25,代碼來源:TestNewDateFunctions.java

示例2: testUnixTimeStampForDate

import org.joda.time.format.DateTimeFormatter; //導入方法依賴的package包/類
@Test
public void testUnixTimeStampForDate() throws Exception {
  DateTimeFormatter formatter = DateFunctionsUtils.getFormatterForFormatString("YYYY-MM-DD HH24:MI:SS");
  date = formatter.parseLocalDateTime("2009-03-20 11:30:01");
  unixTimeStamp = com.dremio.common.util.DateTimes.toMillis(date) / 1000;
  testBuilder()
      .sqlQuery("select unix_timestamp('2009-03-20 11:30:01') from cp.`employee.json` limit 1")
      .ordered()
      .baselineColumns("EXPR$0")
      .baselineValues(unixTimeStamp)
      .build().run();

  date = formatter.parseLocalDateTime("2014-08-09 05:15:06");
  unixTimeStamp = com.dremio.common.util.DateTimes.toMillis(date) / 1000;
  testBuilder()
      .sqlQuery("select unix_timestamp('2014-08-09 05:15:06') from cp.`employee.json` limit 1")
      .ordered()
      .baselineColumns("EXPR$0")
      .baselineValues(unixTimeStamp)
      .build().run();

  date = formatter.parseLocalDateTime("1970-01-01 00:00:00");
  unixTimeStamp = com.dremio.common.util.DateTimes.toMillis(date) / 1000;
  testBuilder()
      .sqlQuery("select unix_timestamp('1970-01-01 00:00:00') from cp.`employee.json` limit 1")
      .ordered()
      .baselineColumns("EXPR$0")
      .baselineValues(unixTimeStamp)
      .build().run();

  // make sure we support 24 hour notation by default
  date = formatter.parseLocalDateTime("1970-01-01 23:12:12");
  unixTimeStamp = com.dremio.common.util.DateTimes.toMillis(date) / 1000;
  testBuilder()
    .sqlQuery("select unix_timestamp('1970-01-01 23:12:12') from cp.`employee.json` limit 1")
    .ordered()
    .baselineColumns("EXPR$0")
    .baselineValues(unixTimeStamp)
    .build().run();
}
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:41,代碼來源:TestNewDateFunctions.java

示例3: testTimeIntervals

import org.joda.time.format.DateTimeFormatter; //導入方法依賴的package包/類
@Test
public void testTimeIntervals() throws Exception {
  HistogramGenerator hg = new HistogramGenerator(null);

  String myTimeStr = "2016-02-29 13:59:01";
  DateTimeFormatter dtf = DateFunctionsUtils.getFormatterForFormatString("YYYY-MM-DD HH24:MI:SS");
  LocalDateTime myTime = dtf.parseLocalDateTime(myTimeStr);
  System.out.println("Exact time: " + myTime + ", Month: " + myTime.getMonthOfYear());
  for (HistogramGenerator.TruncEvalEnum value : HistogramGenerator.TruncEvalEnum.getSortedAscValues()) {
    LocalDateTime roundedDown = hg.roundTime(myTime, value, true);
    LocalDateTime roundedUp = hg.roundTime(myTime, value, false);
    switch(value) {
      case SECOND:
        assertEquals(myTime, roundedDown);
        assertEquals(myTime, roundedUp);
        break;
      case MINUTE:
        assertEquals(dtf.parseLocalDateTime("2016-02-29 13:59:00"), roundedDown);
        assertEquals(dtf.parseLocalDateTime("2016-02-29 14:00:00"), roundedUp);
        break;
      case HOUR:
        assertEquals(dtf.parseLocalDateTime("2016-02-29 13:00:00"), roundedDown);
        assertEquals(dtf.parseLocalDateTime("2016-02-29 14:00:00"), roundedUp);
        break;
      case DAY:
        assertEquals(dtf.parseLocalDateTime("2016-02-29 00:00:00"), roundedDown);
        assertEquals(dtf.parseLocalDateTime("2016-03-01 00:00:00"), roundedUp);
        break;
      case WEEK:
        assertEquals(dtf.parseLocalDateTime("2016-02-29 00:00:00"), roundedDown);
        assertEquals(dtf.parseLocalDateTime("2016-03-07 00:00:00"), roundedUp);
        break;
      case MONTH:
        assertEquals(dtf.parseLocalDateTime("2016-02-01 00:00:00"), roundedDown);
        assertEquals(dtf.parseLocalDateTime("2016-03-01 00:00:00"), roundedUp);
        break;
      case QUARTER:
        assertEquals(dtf.parseLocalDateTime("2016-01-01 00:00:00"), roundedDown);
        assertEquals(dtf.parseLocalDateTime("2016-04-01 00:00:00"), roundedUp);
        break;
      case YEAR:
        assertEquals(dtf.parseLocalDateTime("2016-01-01 00:00:00"), roundedDown);
        assertEquals(dtf.parseLocalDateTime("2017-01-01 00:00:00"), roundedUp);
        break;
      case DECADE:
        assertEquals(dtf.parseLocalDateTime("2010-01-01 00:00:00"), roundedDown);
        assertEquals(dtf.parseLocalDateTime("2020-01-01 00:00:00"), roundedUp);
        break;
      case CENTURY:
        assertEquals(dtf.parseLocalDateTime("2000-01-01 00:00:00"), roundedDown);
        assertEquals(dtf.parseLocalDateTime("2100-01-01 00:00:00"), roundedUp);
        break;
      case MILLENNIUM:
        assertEquals(dtf.parseLocalDateTime("2000-01-01 00:00:00"), roundedDown);
        assertEquals(dtf.parseLocalDateTime("3000-01-01 00:00:00"), roundedUp);
        break;
      default:
        fail();
    }
  }
}
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:62,代碼來源:TestHistogramGenerator.java


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