當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。