当前位置: 首页>>代码示例>>Java>>正文


Java DateTimeFormatter.parseDateTime方法代码示例

本文整理汇总了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));
     }
 }
 
开发者ID:mazhou,项目名称:es-sql,代码行数:19,代码来源:QueryTest.java

示例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);
	}
}
 
开发者ID:mazhou,项目名称:es-sql,代码行数:21,代码来源:QueryTest.java

示例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));
  }
}
 
开发者ID:logistimo,项目名称:logistimo-web-service,代码行数:21,代码来源:ReportPluginService.java

示例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;
}
 
开发者ID:wulkanowy,项目名称:wulkanowy,代码行数:15,代码来源:TimetableFragmentTab.java

示例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();
    } 
}
 
开发者ID:frictionlessdata,项目名称:tableschema-java,代码行数:15,代码来源:TypeInferrer.java

示例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();
    } 
}
 
开发者ID:frictionlessdata,项目名称:tableschema-java,代码行数:16,代码来源:TypeInferrer.java

示例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));
}
 
开发者ID:frictionlessdata,项目名称:tableschema-java,代码行数:29,代码来源:FieldConstraintsTest.java

示例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);
}
 
开发者ID:shlee89,项目名称:athena,代码行数:6,代码来源:DefaultInfluxMetric.java

示例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);
  }
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:15,代码来源:DateFunctionsUtils.java

示例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();
}
 
开发者ID:jeikerxiao,项目名称:X-mall,代码行数:6,代码来源:DateTimeUtil.java

示例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;
      }
   };
}
 
开发者ID:Alfresco,项目名称:alfresco-remote-api,代码行数:47,代码来源:AbstractCalendarListingWebScript.java

示例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();
}
 
开发者ID:wangshufu,项目名称:mmall,代码行数:11,代码来源:DateTimeUtil.java

示例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();
}
 
开发者ID:prb8025236,项目名称:CheapStore,代码行数:6,代码来源:DateTimeUtil.java

示例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;
  }
 
开发者ID:apache,项目名称:incubator-sdap-mudrod,代码行数:68,代码来源:CrawlerDetection.java

示例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));
    
}
 
开发者ID:frictionlessdata,项目名称:tableschema-java,代码行数:56,代码来源:FieldConstraintsTest.java


注:本文中的org.joda.time.format.DateTimeFormatter.parseDateTime方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。