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


Java DateUtils.parseDate方法代码示例

本文整理汇总了Java中org.apache.commons.lang3.time.DateUtils.parseDate方法的典型用法代码示例。如果您正苦于以下问题:Java DateUtils.parseDate方法的具体用法?Java DateUtils.parseDate怎么用?Java DateUtils.parseDate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.lang3.time.DateUtils的用法示例。


在下文中一共展示了DateUtils.parseDate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testSetInParameter_mapperForLocalDate

import org.apache.commons.lang3.time.DateUtils; //导入方法依赖的package包/类
@Test
public void testSetInParameter_mapperForLocalDate() throws ParseException, SQLException {

	LocalDate localDate = LocalDate.of(2002, Month.JANUARY, 1);
	Date date = DateUtils.parseDate("2002-01-01", new String[] { "yyyy-MM-dd" });
	try (SqlAgent agent = config.agent()) {
		SqlContext ctx = agent.contextFrom("test/PARAM_MAPPING1").param("targetDate", localDate);

		try (ResultSet rs = agent.query(ctx)) {
			assertThat("結果が0件です。", rs.next(), is(true));
			assertThat(rs.getDate("TARGET_DATE"), is(new java.sql.Date(date.getTime())));

			assertThat("取得データが多すぎます", rs.next(), is(false));
		}

	}
}
 
开发者ID:future-architect,项目名称:uroborosql,代码行数:18,代码来源:ParameterTest.java

示例2: testSqlDate

import org.apache.commons.lang3.time.DateUtils; //导入方法依赖的package包/类
@Test
public void testSqlDate() throws ParseException {
	DateParameterMapper mapper = new DateParameterMapper();
	Date date = DateUtils.parseDate("2000/01/01", new String[] { "yyyy/MM/dd" });
	java.sql.Date sqlDate = new java.sql.Date(date.getTime());
	assertThat(mapper.toJdbc(sqlDate, null, null), instanceOf(java.sql.Date.class));
	assertThat(mapper.toJdbc(sqlDate, null, null), is(sqlDate));

	java.sql.Timestamp timestamp = new java.sql.Timestamp(date.getTime());
	assertThat(mapper.toJdbc(timestamp, null, null), instanceOf(java.sql.Timestamp.class));
	assertThat(mapper.toJdbc(timestamp, null, null), is(timestamp));

	java.sql.Time time = new java.sql.Time(date.getTime());
	assertThat(mapper.toJdbc(time, null, null), instanceOf(java.sql.Time.class));
	assertThat(mapper.toJdbc(time, null, null), is(time));
}
 
开发者ID:future-architect,项目名称:uroborosql,代码行数:17,代码来源:DateParameterMapperTest.java

示例3: getDate

import org.apache.commons.lang3.time.DateUtils; //导入方法依赖的package包/类
public static Date getDate(Cell cell, String format) throws ParseException {
    if (isNullCell(cell)) {
        return null;
    }
    switch (cell.getCellType()) {
        case Cell.CELL_TYPE_NUMERIC:// 数字类型
            return getCellDate(cell);
        case Cell.CELL_TYPE_STRING:
            if(StringUtils.isNotEmpty(cell.getStringCellValue())){
                return DateUtils.parseDate(cell.getStringCellValue(), format);
            }else{
                return null;
            }
        default:
            throw new RuntimeException("can not convertWithConstructor cell value to Date!");
    }
}
 
开发者ID:dengxiangjun,项目名称:OfficeAutomation,代码行数:18,代码来源:CellConvert.java

示例4: parse

import org.apache.commons.lang3.time.DateUtils; //导入方法依赖的package包/类
private Date parse(String d) {
        Date date = null;
        try {
            date = DateUtils.parseDate(d.substring(0, 8), "yyyyMMdd");
        } catch (Exception e) {
//            e.printStackTrace();
        }
        return date;
    }
 
开发者ID:jt120,项目名称:take,代码行数:10,代码来源:ParseFenHong.java

示例5: storeData

import org.apache.commons.lang3.time.DateUtils; //导入方法依赖的package包/类
private void storeData(final long tupleId, final List<String> currentRow, final int column)
    throws ParseException {

  final String stringValue = currentRow.get(column);
  switch (this.types.get(column).getSpecificType()) {
    case DOUBLE:
      final Double doubleValue = (stringValue == null) ? null : Double.parseDouble(stringValue);
      this.dataByColumns.get(column).add(new RowIndexedDoubleValue(tupleId, doubleValue));
      break;
    case DATE:
      final Date dateValue =
      (stringValue == null) ? null : DateUtils.parseDate(stringValue,
          TypeInferrer.dateFormats);
      this.dataByColumns.get(column).add(new RowIndexedDateValue(tupleId, dateValue));
      break;
    case LONG:
      final Long longValue = (stringValue == null) ? null : Long.parseLong(stringValue);
      this.dataByColumns.get(column).add(new RowIndexedLongValue(tupleId, longValue));
      break;
    case STRING:
      this.dataByColumns.get(column).add(new RowIndexedStringValue(tupleId, stringValue));
      break;
    default:
      this.dataByColumns.get(column).add(new RowIndexedStringValue(tupleId, stringValue));
      break;
  }
}
 
开发者ID:HPI-Information-Systems,项目名称:metanome-algorithms,代码行数:28,代码来源:ORDER.java

示例6: main

import org.apache.commons.lang3.time.DateUtils; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
  // create the parser
  CommandLineParser parser = new DefaultParser();
  CommandLine line = parser.parse(getOptions(), args);

  // download
  if (line.hasOption("download")) {

    // files directory
    String directory = line.getOptionValue("directory", "hkex/");

    // parse date range
    Date startDate = DateUtils.parseDate(line.getOptionValue("start"), "yyyy/MM/dd");
    Date endDate = DateUtils.parseDate(line.getOptionValue("end"), "yyyy/MM/dd");

    // create spider instance
    Spider spider = new Spider(directory);

    // target market
    String market = line.getOptionValue("market", "all");
    switch (market) {
      case "all":
        spider.downloadRangeForAll(startDate, endDate);
        break;
      case "shanghai":
        spider.downloadRangeForShanghai(startDate, endDate);
        break;
      case "shenzhen":
        spider.downloadRangeForShenZhen(startDate, endDate);
        break;
      case "hongkong":
        spider.downloadRangeForHongKong(startDate, endDate);
        break;
      default:
        throw new IllegalArgumentException(
            "Unexpected value for line option 'market': " + market);
    }
  }
}
 
开发者ID:longkerdandy,项目名称:qfii-tracker,代码行数:40,代码来源:Spider.java

示例7: testSetInParameter_mapperForDate

import org.apache.commons.lang3.time.DateUtils; //导入方法依赖的package包/类
@Test
public void testSetInParameter_mapperForDate() throws ParseException, SQLException {

	Date date = DateUtils.parseDate("2002-01-01", new String[] { "yyyy-MM-dd" });
	try (SqlAgent agent = config.agent()) {
		SqlContext ctx = agent.contextFrom("test/PARAM_MAPPING1").param("targetDate", date);

		try (ResultSet rs = agent.query(ctx)) {
			assertThat("結果が0件です。", rs.next(), is(true));
			assertThat(rs.getDate("TARGET_DATE"), is(new java.sql.Date(date.getTime())));

			assertThat("取得データが多すぎます", rs.next(), is(false));
		}
	}
}
 
开发者ID:future-architect,项目名称:uroborosql,代码行数:16,代码来源:ParameterTest.java

示例8: test

import org.apache.commons.lang3.time.DateUtils; //导入方法依赖的package包/类
@Test
public void test() throws ParseException {
	DateParameterMapper mapper = new DateParameterMapper();
	Date date = DateUtils.parseDate("2000/01/01", new String[] { "yyyy/MM/dd" });
	assertThat(mapper.toJdbc(date, null, null), instanceOf(java.sql.Timestamp.class));

	assertThat(mapper.toJdbc(date, null, null), is(new java.sql.Timestamp(date.getTime())));
}
 
开发者ID:future-architect,项目名称:uroborosql,代码行数:9,代码来源:DateParameterMapperTest.java

示例9: insert

import org.apache.commons.lang3.time.DateUtils; //导入方法依赖的package包/类
public int insert(JSONObject json) throws Exception{
       Date buildDate = null;
       if (!StringUtils.isBlank(json.getString("BUILD_DATE"))) {
       	buildDate = DateUtils.parseDate(json.getString("BUILD_DATE"), Const.FORMAT_DATE);
       }        
       String sql = " INSERT INTO MST_SITE (SITE_ID, SITE_NAME, SITE_TYPE, DIST_CODE, ORG_ID, TEL, BUILD_DATE, DESC_INFO, MASTER, LINE1, LINE2, PARKS, TOTAL_AREA, SITE_IMG, CREATE_BY, CREATE_TIME, UPDATE_BY, UPDATE_TIME) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, SYSTIMESTAMP, ?, SYSTIMESTAMP)";
       Object[] args = { super.generateKey(), json.getString("SITE_NAME"), json.getString("SITE_TYPE"),
   			json.getString("DIST_CODE"), json.getString("ORG_ID"), json.getString("TEL"),
               buildDate, json.getString("DESC_INFO"), json.getString("MASTER"), json.getString("LINE1"),
               json.getString("LINE2"), json.getString("PARKS"), json.getString("TOTAL_AREA"),
               json.getString("SITE_IMG"), json.getString("DETAIL_BY"), json.getString("DETAIL_BY")};
       return super.getJdbcTemplate().update(sql, args);
}
 
开发者ID:craware,项目名称:webapp-tyust,代码行数:14,代码来源:MstSiteDao.java

示例10: update

import org.apache.commons.lang3.time.DateUtils; //导入方法依赖的package包/类
public int update(JSONObject json) throws Exception {
    Date buildDate = null;
    if (!StringUtils.isBlank(json.getString("BUILD_DATE"))) {
    	buildDate = DateUtils.parseDate(json.getString("BUILD_DATE"), Const.FORMAT_DATE);
    }        
    String sql = " UPDATE MST_SITE SET SITE_NAME = ?, SITE_TYPE = ?, DIST_CODE = ?, ORG_ID = ?, TEL = ?, BUILD_DATE = ?, DESC_INFO = ?, MASTER = ?, LINE1 = ?, LINE2 = ?, PARKS = ?, TOTAL_AREA = ?, SITE_IMG = ?, UPDATE_BY = ?, UPDATE_TIME = SYSTIMESTAMP WHERE SITE_ID = ? ";
    Object[] args = { json.getString("SITE_NAME"), json.getString("SITE_TYPE"), json.getString("DIST_CODE"),
            json.getString("ORG_ID"), json.getString("TEL"), buildDate, json.getString("DESC_INFO"), json.getString("MASTER"), 
            json.getString("LINE1"), json.getString("LINE2"), json.getString("PARKS"), json.getString("TOTAL_AREA"),
            json.getString("SITE_IMG"), json.getString("DETAIL_BY"), json.getString("SITE_ID")};         
    return super.getJdbcTemplate().update(sql.toString(), args);
}
 
开发者ID:craware,项目名称:webapp-tyust,代码行数:13,代码来源:MstSiteDao.java

示例11: localTime

import org.apache.commons.lang3.time.DateUtils; //导入方法依赖的package包/类
@BindingAdapter("localTime")
public static void localTime(TextView textView, String time) {
    try {
        Date date = DateUtils.parseDate(time, DATE_FORMATS);

        // TODO マストドンのState時刻が9時間前になっている。原因は?
        date.setTime(date.getTime() + (1000 * 60 * 60 * 9));

        String formatTime = sdf.format(date);
        textView.setText(formatTime);
    } catch (ParseException e) {
        e.printStackTrace();
        textView.setText(time);
    }
}
 
开发者ID:npdess,项目名称:mining,代码行数:16,代码来源:TextViewExtensions.java

示例12: getInterfaceCostStatistics

import org.apache.commons.lang3.time.DateUtils; //导入方法依赖的package包/类
public Map<Date, Double> getInterfaceCostStatistics(InterfaceInfo interfaceInfo, Date endTime, StatisticsUnit statisticsUnit) {
    Date startTime = statisticsUnit.getStartTime(endTime);
    List<String> days = getIntervalDays(startTime, endTime);
    List<String> redisKeys = new ArrayList<>();
    Map<String, String> redisKeyDayMap = new HashMap<>(1 << 4);
    for (String day : days) {
        final String interfaceResultKey = KeyRole.INTERFACE.getRedisKey(null, interfaceInfo, day);
        final String interfaceCostResultKey = KeyRole.INTERFACE_COST.getRedisKey(null, interfaceInfo, day);
        redisKeys.add(interfaceResultKey);
        redisKeys.add(interfaceCostResultKey);
        redisKeyDayMap.put(interfaceResultKey, day);
        redisKeyDayMap.put(interfaceCostResultKey, day);
    }

    List<Map<String, String>> allDatas = getAll(redisKeys);
    List<Pair<Date, Date>> datePairs = getIntervalPoint(endTime, statisticsUnit);
    Map<Date, Double> res = new LinkedHashMap<>();
    for (Pair<Date, Date> datePair : datePairs) {
        int successTimes = 0;
        double cost = 0;

        String thisDay = getCurrentDay(datePair.getRight());
        Date thisDayDate = null;
        try {
            thisDayDate = DateUtils.parseDate(thisDay, "yyMMdd");
        } catch (ParseException e) {
        }
        for (int i = 0; i < redisKeys.size(); i++) {
            Map<String, String> data = allDatas.get(i);
            String redisKey = redisKeys.get(i);
            if (thisDay.equals(redisKeyDayMap.get(redisKey))) {
                for (Map.Entry<String, String> entry : data.entrySet()) {
                    String field = entry.getKey();
                    int minuteIndex = getMinuteIndex(field);
                    long thisTime = thisDayDate.getTime() + minuteIndex * 60 * 1000L;
                    if (thisTime < datePair.getLeft().getTime() && thisTime >= datePair.getRight().getTime()) {
                        int v = Integer.parseInt(entry.getValue());
                        if (field.endsWith("s")) {
                            successTimes += v;
                        } else if (!field.endsWith("f")) {
                            cost += v;
                        }
                    }
                }
            }
        }
        double aveCost = successTimes == 0 ? 0 : cost / successTimes;
        res.put(datePair.getRight(), aveCost);
    }

    return res;
}
 
开发者ID:wxz1211,项目名称:dooo,代码行数:53,代码来源:StatisticsCacheServiceAbstract.java

示例13: parse

import org.apache.commons.lang3.time.DateUtils; //导入方法依赖的package包/类
private List<StockShareholding> parse(Date queryDate, String directory)
    throws IOException, ParseException {
  // parse html from downloaded HKEX files
  File input = new File(directory + DateFormatUtils.format(queryDate, "yyyyMMdd") + ".html");
  if (!input.exists()) {
    return Collections.emptyList();
  }
  Document doc = Jsoup.parse(input, "UTF-8", "http://sc.hkexnews.hk");

  // parse actual query date
  Date actualDate = null;
  Elements divs = doc.select("div#pnlResult > div");
  for (Element div : divs) {
    if (div.text().startsWith("持股日期")) {
      actualDate = DateUtils
          .parseDate(div.text().substring(div.text().length() - 10), "dd/MM/yyyy");
      break;
    }
  }
  if (actualDate == null) {
    throw new IllegalStateException("Date not present in the query result");
  }

  // result
  List<StockShareholding> stockShareholdings = new ArrayList<>();

  // parse shareholding data
  Elements rows = doc.select("tr.row0,tr.row1");
  for (Element row : rows) {
    StockShareholding stockShareholding = new StockShareholding();
    stockShareholding.setDate(actualDate);
    stockShareholding.setCode(adjustCode(row.child(0).ownText()));
    stockShareholding.setName(adjustName(row.child(1).ownText()));
    stockShareholding
        .setShareholding(NumberUtils.toLong(row.child(2).ownText().replaceAll(",", "")));
    stockShareholding
        .setPercent(NumberUtils.toFloat(row.child(3).ownText().replaceAll("%", "")) / 100);
    stockShareholdings.add(stockShareholding);
  }

  return stockShareholdings;
}
 
开发者ID:longkerdandy,项目名称:qfii-tracker,代码行数:43,代码来源:ConnectParser.java

示例14: main

import org.apache.commons.lang3.time.DateUtils; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
  // create the parser
  CommandLineParser parser = new DefaultParser();
  CommandLine line = parser.parse(getOptions(), args);

  // config file
  PropertiesConfiguration config = new PropertiesConfiguration(
      line.getOptionValue("config", "config/tracker.properties"));

  // storage
  PostgreStorage storage = new PostgreStorage(config.getString("storage.url"),
      config.getString("storage.username"), config.getString("storage.password"));

  // target market
  String market = line.getOptionValue("market", "all");

  // clear
  if (line.hasOption("clear")) {
    storage.clear(market);
    logger.info("Data has been cleared");
  }

  // update
  if (line.hasOption("update")) {
    // files directory
    String directory = line.getOptionValue("directory", "hkex/");

    // parse date range and update storage
    Date startDate = DateUtils.parseDate(line.getOptionValue("start"), "yyyy/MM/dd");
    Date endDate = DateUtils.parseDate(line.getOptionValue("end"), "yyyy/MM/dd");

    // create tracker instance
    Tracker tracker = new Tracker(directory, storage);

    // target market
    switch (market) {
      case "all":
        tracker.parseRangeForAll(startDate, endDate);
        break;
      case "shanghai":
        tracker.parseRangeForShanghai(startDate, endDate);
        break;
      case "shenzhen":
        tracker.parseRangeForShenZhen(startDate, endDate);
        break;
      case "hongkong":
        tracker.parseRangeForHongKong(startDate, endDate);
        break;
      default:
        throw new IllegalArgumentException(
            "Unexpected value for line option 'market': " + market);
    }

    logger.info("Market {} date {} to {} data has been updated", market,
        line.getOptionValue("start"), line.getOptionValue("end"));
  }
}
 
开发者ID:longkerdandy,项目名称:qfii-tracker,代码行数:58,代码来源:Tracker.java

示例15: getStatistics

import org.apache.commons.lang3.time.DateUtils; //导入方法依赖的package包/类
private Map<Date, StatisticsDetail> getStatistics(KeyRole keyRole, AppInfo appInfo, InterfaceInfo interfaceInfo, Date endTime,
                                                  StatisticsUnit statisticsUnit) {
    Date startTime = statisticsUnit.getStartTime(endTime);
    List<String> days = getIntervalDays(startTime, endTime);
    List<String> redisKeys = new ArrayList<>();
    Map<String, String> redisKeyDayMap = new HashMap<>(days.size());
    for (String day : days) {
        final String appInterfaceResultKey = keyRole.getRedisKey(appInfo, interfaceInfo, day);
        redisKeys.add(appInterfaceResultKey);
        redisKeyDayMap.put(appInterfaceResultKey, day);
    }

    List<Map<String, String>> allDatas = getAll(redisKeys);
    List<Pair<Date, Date>> datePairs = getIntervalPoint(endTime, statisticsUnit);
    Map<Date, StatisticsDetail> res = new LinkedHashMap<>();
    for (   Pair<Date, Date> datePair : datePairs) {
        StatisticsDetail statisticsDetail = new StatisticsDetail();
        int totalTimes = 0;
        int successTimes = 0;
        int failTimes = 0;
        res.put(datePair.getRight(), statisticsDetail);

        String thisDay = getCurrentDay(datePair.getRight());
        Date thisDayDate = null;
        try {
            thisDayDate = DateUtils.parseDate(thisDay, "yyMMdd");
        } catch (ParseException e) {
        }
        for (int i = 0; i < redisKeys.size(); i++) {
            Map<String, String> data = new TreeMap<>(allDatas.get(i));
            String redisKey = redisKeys.get(i);
            if (thisDay.equals(redisKeyDayMap.get(redisKey))) {
                for (Map.Entry<String, String> entry : data.entrySet()) {
                    String field = entry.getKey();
                    int minuteIndex = getMinuteIndex(field);
                    long thisTime = thisDayDate.getTime() + minuteIndex * 60 * 1000L;
                    if (thisTime < datePair.getLeft().getTime() && thisTime >= datePair.getRight().getTime()) {
                        int v = Integer.parseInt(entry.getValue());
                        totalTimes += v;
                        if (field.endsWith("s")) {
                            successTimes += v;
                        } else if (field.endsWith("f")) {
                            failTimes += v;
                        }
                    }
                }
            }
        }
        statisticsDetail.setTotalTimes(totalTimes);
        statisticsDetail.setSuccessTimes(successTimes);
        statisticsDetail.setFailTimes(failTimes);
    }

    return res;
}
 
开发者ID:wxz1211,项目名称:dooo,代码行数:56,代码来源:StatisticsCacheServiceAbstract.java


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