本文整理汇总了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();
}
示例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();
}
示例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();
}
}
}