本文整理汇总了Java中org.joda.time.format.DateTimeFormatter.parseDateTime方法的典型用法代码示例。如果您正苦于以下问题:Java DateTimeFormatter.parseDateTime方法的具体用法?Java DateTimeFormatter.parseDateTime怎么用?Java DateTimeFormatter.parseDateTime使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.joda.time.format.DateTimeFormatter
的用法示例。
在下文中一共展示了DateTimeFormatter.parseDateTime方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: dateSearchBraces
import org.joda.time.format.DateTimeFormatter; //导入方法依赖的package包/类
@Test
public void dateSearchBraces() throws IOException, SqlParseException, SQLFeatureNotSupportedException, ParseException {
DateTimeFormatter formatter = DateTimeFormat.forPattern(TS_DATE_FORMAT);
DateTime dateToCompare = new DateTime(2015, 3, 15, 0, 0, 0);
SearchHits response = query(String.format("SELECT odbc_time FROM %s/odbc WHERE odbc_time < {ts '2015-03-15 00:00:00.000'}", TEST_INDEX));
SearchHit[] hits = response.getHits();
for(SearchHit hit : hits) {
Map<String, Object> source = hit.getSource();
String insertTimeStr = (String) source.get("odbc_time");
insertTimeStr = insertTimeStr.replace("{ts '", "").replace("'}", "");
DateTime insertTime = formatter.parseDateTime(insertTimeStr);
String errorMessage = String.format("insert_time must be smaller then 2015-03-15. found: %s", insertTime);
Assert.assertTrue(errorMessage, insertTime.isBefore(dateToCompare));
}
}
示例2: dateBetweenSearch
import org.joda.time.format.DateTimeFormatter; //导入方法依赖的package包/类
@Test
public void dateBetweenSearch() throws IOException, SqlParseException, SQLFeatureNotSupportedException {
DateTimeFormatter formatter = DateTimeFormat.forPattern(DATE_FORMAT);
DateTime dateLimit1 = new DateTime(2014, 8, 18, 0, 0, 0);
DateTime dateLimit2 = new DateTime(2014, 8, 21, 0, 0, 0);
SearchHits response = query(String.format("SELECT insert_time FROM %s/online WHERE insert_time BETWEEN '2014-08-18' AND '2014-08-21' LIMIT 3", TEST_INDEX));
SearchHit[] hits = response.getHits();
for(SearchHit hit : hits) {
Map<String, Object> source = hit.getSource();
DateTime insertTime = formatter.parseDateTime((String) source.get("insert_time"));
boolean isBetween =
(insertTime.isAfter(dateLimit1) || insertTime.isEqual(dateLimit1)) &&
(insertTime.isBefore(dateLimit2) || insertTime.isEqual(dateLimit2));
Assert.assertTrue("insert_time must be between 2014-08-18 and 2014-08-21", isBetween);
}
}
示例3: getReportTableStartTime
import org.joda.time.format.DateTimeFormatter; //导入方法依赖的package包/类
private String getReportTableStartTime(JSONObject jsonObject, String endTime)
throws ParseException {
switch (jsonObject.getString(QueryHelper.PERIODICITY)) {
case QueryHelper.PERIODICITY_MONTH:
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM");
Calendar toDate = new GregorianCalendar();
toDate.setTime(format.parse(endTime));
toDate.add(Calendar.MONTH, -1*(QueryHelper.MONTHS_LIMIT-1));
return format.format(toDate.getTime());
case QueryHelper.PERIODICITY_WEEK:
DateTimeFormatter mDateTimeFormatter = DateTimeFormat.forPattern(
QueryHelper.DATE_FORMAT_DAILY);
DateTime toTime = mDateTimeFormatter.parseDateTime(endTime);
return mDateTimeFormatter.print(toTime.minusWeeks(QueryHelper.WEEKS_LIMIT-1));
default:
mDateTimeFormatter = DateTimeFormat.forPattern(QueryHelper.DATE_FORMAT_DAILY);
toTime = mDateTimeFormatter.parseDateTime(endTime);
return mDateTimeFormatter.print(toTime.minusDays(QueryHelper.DAYS_LIMIT-1));
}
}
示例4: getExpanded
import org.joda.time.format.DateTimeFormatter; //导入方法依赖的package包/类
private boolean getExpanded(String dayDate) {
DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern(DATE_PATTERN);
DateTime dayTime = dateTimeFormatter.parseDateTime(dayDate);
DateTime currentDate = new DateTime();
if (currentDate.getDayOfWeek() == DateTimeConstants.SATURDAY) {
currentDate = currentDate.plusDays(2);
} else if (currentDate.getDayOfWeek() == DateTimeConstants.SUNDAY) {
currentDate = currentDate.plusDays(1);
}
return DateTimeComparator.getDateOnlyInstance().compare(currentDate, dayTime) == 0;
}
示例5: castTime
import org.joda.time.format.DateTimeFormatter; //导入方法依赖的package包/类
public DateTime castTime(String format, String value, Map<String, Object> options) throws TypeInferringException{
Pattern pattern = Pattern.compile(REGEX_TIME);
Matcher matcher = pattern.matcher(value);
if(matcher.matches()){
DateTimeFormatter formatter = DateTimeFormat.forPattern("HH:mm:ss");
DateTime dt = formatter.parseDateTime(value);
return dt;
}else{
throw new TypeInferringException();
}
}
示例6: castDate
import org.joda.time.format.DateTimeFormatter; //导入方法依赖的package包/类
public DateTime castDate(String format, String value, Map<String, Object> options) throws TypeInferringException{
Pattern pattern = Pattern.compile(REGEX_DATE);
Matcher matcher = pattern.matcher(value);
if(matcher.matches()){
DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd");
DateTime dt = formatter.parseDateTime(value);
return dt;
}else{
throw new TypeInferringException();
}
}
示例7: testEnumDatetime
import org.joda.time.format.DateTimeFormatter; //导入方法依赖的package包/类
@Test
public void testEnumDatetime(){
Map<String, Object> violatedConstraints = null;
Map<String, Object> constraints = new HashMap();
List<DateTime> enumDatetimes = new ArrayList();
DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
DateTime datetime1 = formatter.parseDateTime("2000-01-15T13:44:33.000Z");
enumDatetimes.add(datetime1);
DateTime datetime2 = formatter.parseDateTime("2019-01-15T13:44:33.000Z");
enumDatetimes.add(datetime2);
constraints.put(Field.CONSTRAINT_KEY_ENUM, enumDatetimes);
Field field = new Field("test", Field.FIELD_TYPE_DATETIME, null, null, null, constraints);
violatedConstraints = field.checkConstraintViolations(datetime1);
Assert.assertTrue(violatedConstraints.isEmpty());
violatedConstraints = field.checkConstraintViolations(datetime2);
Assert.assertTrue(violatedConstraints.isEmpty());
DateTime datetime3 = formatter.parseDateTime("2003-01-15T13:44:33.000Z");
violatedConstraints = field.checkConstraintViolations(datetime3);
Assert.assertTrue(violatedConstraints.containsKey(Field.CONSTRAINT_KEY_ENUM));
}
示例8: parseTime
import org.joda.time.format.DateTimeFormatter; //导入方法依赖的package包/类
private DateTime parseTime(String time) {
String reformatTime = StringUtils.replace(StringUtils.replace(time, "T", " "), "Z", "");
DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
return formatter.parseDateTime(reformatTime);
}
示例9: formatDate
import org.joda.time.format.DateTimeFormatter; //导入方法依赖的package包/类
public static long formatDate(String input, DateTimeFormatter format) {
try {
final DateTime dateTime = format.parseDateTime(input);
// Subtract out the time part in DateTime
return com.dremio.common.util.DateTimes.toMillis(dateTime) - dateTime.millisOfDay().get();
} catch (IllegalArgumentException ex) {
throw UserException.functionError(ex)
.message("Input text cannot be formatted to date")
.addContext("Details", ex.getMessage())
.addContext("Input text", input)
.build(logger);
}
}
示例10: strToDate
import org.joda.time.format.DateTimeFormatter; //导入方法依赖的package包/类
public static Date strToDate(String dateTimeStr, String formatStr) {
DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern(formatStr);
DateTime dateTime = dateTimeFormatter.parseDateTime(dateTimeStr);
return dateTime.toDate();
}
示例11: getEventDetailsSorter
import org.joda.time.format.DateTimeFormatter; //导入方法依赖的package包/类
/**
* Returns a Comparator for (re-)sorting events, typically used after
* expanding out recurring instances.
*/
protected static Comparator<Map<String, Object>> getEventDetailsSorter()
{
return new Comparator<Map<String, Object>>()
{
public int compare(Map<String, Object> resultA,
Map<String, Object> resultB)
{
DateTimeFormatter fmtNoTz = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSS");
DateTimeFormatter fmtTz = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZZ");
String startA = (String)resultA.get(RESULT_START);
String startB = (String)resultB.get(RESULT_START);
startA = startA.replace("Z", "+00:00");
startB = startB.replace("Z", "+00:00");
//check and parse iso8601 date without time zone (All day events are stripped of time zone)
DateTime sa = startA.length()>23?fmtTz.parseDateTime(startA):fmtNoTz.parseDateTime(startA);
DateTime sb = startB.length()>23?fmtTz.parseDateTime(startB):fmtNoTz.parseDateTime(startB);
int cmp = sa.compareTo(sb);
if (cmp == 0)
{
String endA = (String)resultA.get(RESULT_END);
String endB = (String)resultB.get(RESULT_END);
DateTime ea = endA.length()>23?fmtTz.parseDateTime(endA):fmtNoTz.parseDateTime(endA);
DateTime eb = endB.length()>23?fmtTz.parseDateTime(endB):fmtNoTz.parseDateTime(endB);
cmp = ea.compareTo(eb);
if (cmp == 0)
{
String nameA = (String)resultA.get(RESULT_NAME);
String nameB = (String)resultB.get(RESULT_NAME);
return nameA.compareTo(nameB);
}
return cmp;
}
return cmp;
}
};
}
示例12: strToDate
import org.joda.time.format.DateTimeFormatter; //导入方法依赖的package包/类
/**
* 当前时间-->2017-08-02 23:19:00
* @param dateTimeStr
* @return
*/
public static Date strToDate(String dateTimeStr){
DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern(STANDARD_FORMAT);
DateTime dateTime = dateTimeFormatter.parseDateTime(dateTimeStr);
return dateTime.toDate();
}
示例13: strToDate
import org.joda.time.format.DateTimeFormatter; //导入方法依赖的package包/类
public static Date strToDate(String dateTimeStr,String formatStr){
DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern(formatStr);
DateTime dateTime = dateTimeFormatter.parseDateTime(dateTimeStr);
return dateTime.toDate();
}
示例14: checkByRate
import org.joda.time.format.DateTimeFormatter; //导入方法依赖的package包/类
private int checkByRate(ESDriver es, String user) {
int rate = Integer.parseInt(props.getProperty("sendingrate"));
Pattern pattern = Pattern.compile("get (.*?) http/*");
Matcher matcher;
BoolQueryBuilder filterSearch = new BoolQueryBuilder();
filterSearch.must(QueryBuilders.termQuery("IP", user));
AggregationBuilder aggregation = AggregationBuilders.dateHistogram("by_minute").field("Time").dateHistogramInterval(DateHistogramInterval.MINUTE).order(Order.COUNT_DESC);
SearchResponse checkRobot = es.getClient().prepareSearch(logIndex).setTypes(httpType, ftpType).setQuery(filterSearch).setSize(0).addAggregation(aggregation).execute().actionGet();
Histogram agg = checkRobot.getAggregations().get("by_minute");
List<? extends Histogram.Bucket> botList = agg.getBuckets();
long maxCount = botList.get(0).getDocCount();
if (maxCount >= rate) {
return 0;
} else {
DateTime dt1 = null;
int toLast = 0;
SearchResponse scrollResp = es.getClient().prepareSearch(logIndex).setTypes(httpType, ftpType).setScroll(new TimeValue(60000)).setQuery(filterSearch).setSize(100).execute().actionGet();
while (true) {
for (SearchHit hit : scrollResp.getHits().getHits()) {
Map<String, Object> result = hit.getSource();
String logtype = (String) result.get("LogType");
if (logtype.equals("PO.DAAC")) {
String request = (String) result.get("Request");
matcher = pattern.matcher(request.trim().toLowerCase());
boolean find = false;
while (matcher.find()) {
request = matcher.group(1);
result.put("RequestUrl", "http://podaac.jpl.nasa.gov" + request);
find = true;
}
if (!find) {
result.put("RequestUrl", request);
}
} else {
result.put("RequestUrl", result.get("Request"));
}
DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
DateTime dt2 = fmt.parseDateTime((String) result.get("Time"));
if (dt1 == null) {
toLast = 0;
} else {
toLast = Math.abs(Seconds.secondsBetween(dt1, dt2).getSeconds());
}
result.put("ToLast", toLast);
IndexRequest ir = new IndexRequest(logIndex, cleanupType).source(result);
es.getBulkProcessor().add(ir);
dt1 = dt2;
}
scrollResp = es.getClient().prepareSearchScroll(scrollResp.getScrollId()).setScroll(new TimeValue(600000)).execute().actionGet();
if (scrollResp.getHits().getHits().length == 0) {
break;
}
}
}
return 1;
}
示例15: testMinimumAndMaximumTime
import org.joda.time.format.DateTimeFormatter; //导入方法依赖的package包/类
@Test
public void testMinimumAndMaximumTime(){
Map<String, Object> violatedConstraints = null;
final String TIME_STRING_MINIMUM = "11:05:12";
final String TIME_STRING_MAXIMUM = "14:22:33";
DateTimeFormatter formatter = DateTimeFormat.forPattern("HH:mm:ss");
DateTime timeMin = formatter.parseDateTime(TIME_STRING_MINIMUM);
DateTime timeMax = formatter.parseDateTime(TIME_STRING_MAXIMUM);
Map<String, Object> constraints = new HashMap();
constraints.put(Field.CONSTRAINT_KEY_MINIMUM, timeMin);
constraints.put(Field.CONSTRAINT_KEY_MAXIMUM, timeMax);
Field field = new Field("test", Field.FIELD_TYPE_TIME, null, null, null, constraints);
DateTime time = formatter.parseDateTime("13:00:05");
violatedConstraints = field.checkConstraintViolations(time);
Assert.assertTrue(violatedConstraints.isEmpty());
DateTime timeEqualMin = formatter.parseDateTime(TIME_STRING_MINIMUM);
violatedConstraints = field.checkConstraintViolations(timeEqualMin);
Assert.assertTrue(violatedConstraints.isEmpty());
DateTime timeEqualMax = formatter.parseDateTime(TIME_STRING_MAXIMUM);
violatedConstraints = field.checkConstraintViolations(timeEqualMax);
Assert.assertTrue(violatedConstraints.isEmpty());
DateTime timeLesserThanMinBy1Sec = formatter.parseDateTime("11:05:11");
violatedConstraints = field.checkConstraintViolations(timeLesserThanMinBy1Sec);
Assert.assertTrue(violatedConstraints.containsKey(Field.CONSTRAINT_KEY_MINIMUM));
DateTime timeLesserThanMinBy1Min = formatter.parseDateTime("11:04:12");
violatedConstraints = field.checkConstraintViolations(timeLesserThanMinBy1Min);
Assert.assertTrue(violatedConstraints.containsKey(Field.CONSTRAINT_KEY_MINIMUM));
DateTime timeLesserThanMinBy1Hour = formatter.parseDateTime("10:05:12");
violatedConstraints = field.checkConstraintViolations(timeLesserThanMinBy1Hour);
Assert.assertTrue(violatedConstraints.containsKey(Field.CONSTRAINT_KEY_MINIMUM));
DateTime timeGreaterThanMaxBy1Sec = formatter.parseDateTime("14:22:34");
violatedConstraints = field.checkConstraintViolations(timeGreaterThanMaxBy1Sec);
Assert.assertTrue(violatedConstraints.containsKey(Field.CONSTRAINT_KEY_MAXIMUM));
DateTime timeGreaterThanMaxBy1Min = formatter.parseDateTime("14:23:33");
violatedConstraints = field.checkConstraintViolations(timeGreaterThanMaxBy1Min);
Assert.assertTrue(violatedConstraints.containsKey(Field.CONSTRAINT_KEY_MAXIMUM));
DateTime timeGreaterThanMaxBy1Hour = formatter.parseDateTime("15:22:33");
violatedConstraints = field.checkConstraintViolations(timeGreaterThanMaxBy1Hour);
Assert.assertTrue(violatedConstraints.containsKey(Field.CONSTRAINT_KEY_MAXIMUM));
}