本文整理匯總了Java中org.apache.commons.lang.time.DateUtils.parseDate方法的典型用法代碼示例。如果您正苦於以下問題:Java DateUtils.parseDate方法的具體用法?Java DateUtils.parseDate怎麽用?Java DateUtils.parseDate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.lang.time.DateUtils
的用法示例。
在下文中一共展示了DateUtils.parseDate方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getDateOfRelease
import org.apache.commons.lang.time.DateUtils; //導入方法依賴的package包/類
public Date getDateOfRelease() {
if (StringUtils.isEmpty(releaseDate)) {
return null;
}
try {
return DateUtils.parseDate(this.releaseDate, new String[]{"yyyy-MM-dd"});
} catch (ParseException e) {
return null;
}
}
示例2: parseDate
import org.apache.commons.lang.time.DateUtils; //導入方法依賴的package包/類
/**
* Parses a date using a set of date patterns. Returns null if String couldn't be parsed.
*
* @param dateString date as String
* @return date from String or null if String is not parseable
*/
private Date parseDate(String dateString){
if(dateString==null||dateString.isEmpty()){
return null;
}
String[] datePatterns = new String[] {
"yyyy-MM-dd'T'HH:mm a",
"yyyy-MM-dd'T'",
"yyyy-MM-dd'T'HH:mm:ssXXX",
"yyyy-MM-dd'T'HH:mm",
"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'",
"yyyy-MM-dd'T'HH:mm:ss",
"yyyy-MM-dd'T'HH:mm:ssXX" };
try{
return DateUtils.parseDate(dateString,datePatterns);
}catch(Exception e){
logger.warn("Could not parse date: "+dateString);
return null;
}
}
示例3: modifyReleaseForm
import org.apache.commons.lang.time.DateUtils; //導入方法依賴的package包/類
/**
* 更改發布單
*
* @param appId
* @param formId 發布單ID
* @param name 發布單名稱
* @param remark 發布單備注
* @param planPubTime 計劃發布時間
* @return
*/
@RequestMapping(value = "/apps/{appId}/releaseform/{formId}", method = RequestMethod.PUT)
@ResponseBody
public Object modifyReleaseForm(@PathVariable("appId") int appId,
@PathVariable("formId") long formId,
@RequestParam("name") String name,
@RequestParam("remark") String remark, @RequestParam("planPubTime") String planPubTime) throws ParseException {
Date planPubDate = null;
if (StringUtils.isNotEmpty(planPubTime)) {
planPubDate = DateUtils.parseDate(planPubTime, new String[]{"yyyy-MM-dd HH:mm:ss"});
}
releaseFormService.modifyForm(appId, formId, name, remark, planPubDate);
return releaseFormService.getReleaseForm(formId);
}
示例4: exec
import org.apache.commons.lang.time.DateUtils; //導入方法依賴的package包/類
@Override
public String exec(final Tuple tuple) throws IOException {
if (tuple == null || tuple.size() == 0) {
return null;
}
Object dateString = tuple.get(0);
if (dateString == null) {
return null;
}
try {
Date date = DateUtils.parseDate(dateString.toString(), new String[]{"yyyy-MM-dd HH:mm:ss"});
return DateFormatUtils.format(date, formatPattern);
} catch (ParseException e) {
e.printStackTrace();
}
return null;
}
示例5: convertDate
import org.apache.commons.lang.time.DateUtils; //導入方法依賴的package包/類
/**
* Dateオブジェクトを作成する.
* objがDate型の場合は、そのままの內容を返す.
* @param obj 対象のオブジェクト
* @param format 書式
* @return 生成した文字列
*/
private Date convertDate(Object obj, String format) {
Date result = null;
try {
if (null != obj) {
if (obj instanceof Date) {
result = (Date) obj;
} else if (obj instanceof oracle.sql.Datum) {
if (obj instanceof oracle.sql.TIMESTAMP) {
java.sql.Timestamp t
= (java.sql.Timestamp) ((oracle.sql.TIMESTAMP) obj).toJdbc();
result = new Date(t.getTime());
} else if (obj instanceof oracle.sql.DATE) {
java.sql.Date d
= (java.sql.Date) ((oracle.sql.DATE) obj).toJdbc();
result = new Date(d.getTime());
} else {
throw new IllegalArgumentException(
"not implemented. type[" + obj.getClass().toString() + "]");
}
} else {
result = DateUtils.parseDate(
obj.toString(), new String[] {format});
}
}
} catch (ParseException pe) {
pe.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return result;
}
示例6: getDateOfCreate
import org.apache.commons.lang.time.DateUtils; //導入方法依賴的package包/類
public Date getDateOfCreate() {
if (StringUtils.isEmpty(createDate)) {
return null;
}
try {
return DateUtils.parseDate(this.createDate, new String[]{"yyyy-MM-dd"});
} catch (ParseException e) {
return null;
}
}
示例7: pageList
import org.apache.commons.lang.time.DateUtils; //導入方法依賴的package包/類
@RequestMapping("/pageList")
@ResponseBody
public Map<String, Object> pageList(@RequestParam(required = false, defaultValue = "0") int start,
@RequestParam(required = false, defaultValue = "10") int length,
int jobGroup, int jobId, int logStatus, String filterTime) {
// parse param
Date triggerTimeStart = null;
Date triggerTimeEnd = null;
if (StringUtils.isNotBlank(filterTime)) {
String[] temp = filterTime.split(" - ");
if (temp!=null && temp.length == 2) {
try {
triggerTimeStart = DateUtils.parseDate(temp[0], new String[]{"yyyy-MM-dd HH:mm:ss"});
triggerTimeEnd = DateUtils.parseDate(temp[1], new String[]{"yyyy-MM-dd HH:mm:ss"});
} catch (ParseException e) { }
}
}
// page query
List<XxlJobLog> list = xxlJobLogDao.pageList(start, length, jobGroup, jobId, triggerTimeStart, triggerTimeEnd, logStatus);
int list_count = xxlJobLogDao.pageListCount(start, length, jobGroup, jobId, triggerTimeStart, triggerTimeEnd, logStatus);
// package result
Map<String, Object> maps = new HashMap<String, Object>();
maps.put("recordsTotal", list_count); // 總記錄數
maps.put("recordsFiltered", list_count); // 過濾後的總記錄數
maps.put("data", list); // 分頁列表
return maps;
}
示例8: pageList
import org.apache.commons.lang.time.DateUtils; //導入方法依賴的package包/類
@RequestMapping("/pageList")
@ResponseBody
public Map<String, Object> pageList(@RequestParam(required = false, defaultValue = "0") int start,
@RequestParam(required = false, defaultValue = "10") int length,
int jobGroup, int jobId, String filterTime) {
// parse param
Date triggerTimeStart = null;
Date triggerTimeEnd = null;
if (StringUtils.isNotBlank(filterTime)) {
String[] temp = filterTime.split(" - ");
if (temp!=null && temp.length == 2) {
try {
triggerTimeStart = DateUtils.parseDate(temp[0], new String[]{"yyyy-MM-dd HH:mm:ss"});
triggerTimeEnd = DateUtils.parseDate(temp[1], new String[]{"yyyy-MM-dd HH:mm:ss"});
} catch (ParseException e) { }
}
}
// page query
List<XxlJobLog> list = xxlJobLogDao.pageList(start, length, jobGroup, jobId, triggerTimeStart, triggerTimeEnd);
int list_count = xxlJobLogDao.pageListCount(start, length, jobGroup, jobId, triggerTimeStart, triggerTimeEnd);
// package result
Map<String, Object> maps = new HashMap<String, Object>();
maps.put("recordsTotal", list_count); // 總記錄數
maps.put("recordsFiltered", list_count); // 過濾後的總記錄數
maps.put("data", list); // 分頁列表
return maps;
}
示例9: getValue
import org.apache.commons.lang.time.DateUtils; //導入方法依賴的package包/類
/**
* 判斷data的類型,嘗試解析成日期類型(返回{@link Date}),其次布爾類型(返回{@link Boolean}),
* 然後數字類型(轉變成字符串輸出),
* 前三種均解析失敗則直接返回字符串data
*
* @param data
* @return 解析後的值
*/
private Object getValue(String data) {
Object value = null;
try {
//判斷是否是日期類型
Date date = DateUtils.parseDate(data, DATE_PATTERN);
value = date;
} catch (ParseException e) {
//拋異常證明非日期類型
if ("true".equalsIgnoreCase(data)) {
value = Boolean.TRUE;
} else if ("false".equalsIgnoreCase(data)) {
value = Boolean.FALSE;
} else {
//判斷是否數字
try {
double dbl = Double.parseDouble(data);
if (this.scale == null || this.scale <= 0) {
//不四舍五入,直接輸出
value = data;
} else {
BigDecimal bd = new BigDecimal(dbl);
value = bd.toString().contains(".") ? bd.setScale(this.scale, RoundingMode.HALF_UP).toString() :
bd.toString();
}
} catch (NumberFormatException e1) {
//證明不是數字,直接輸出
value = data;
}
}
}
return value;
}
示例10: getCellValue
import org.apache.commons.lang.time.DateUtils; //導入方法依賴的package包/類
/**
* 獲取指定單元格的內容。隻能是日期(返回java.util.Date),整數值(返回的均是String類型),小數值(返回的均是String類型,並
* 保留兩位小數),字符串, 布爾類型。 其他類型返回null。
*
* @param type 指定類型(Cell中定義的類型)
* @param cell 指定單元格
* @return 返回Cell裏的內容
*/
public static Object getCellValue(int type, Cell cell) {
switch (type) {
case Cell.CELL_TYPE_BOOLEAN:
return cell.getBooleanCellValue();
case Cell.CELL_TYPE_NUMERIC:
if (DateUtil.isCellDateFormatted(cell)) {
return DateUtil.getJavaDate(cell.getNumericCellValue());
} else {
BigDecimal bd = new BigDecimal(cell.getNumericCellValue());
return bd.toString().contains(".") ? bd.setScale(2, RoundingMode.HALF_UP).toString() :
bd.toString();
}
case Cell.CELL_TYPE_STRING:
try {
return DateUtils.parseDate(cell.getStringCellValue(), ReadExcelUtils.pattern);
} catch (Exception e) {
return cell.getStringCellValue();
}
case Cell.CELL_TYPE_FORMULA:
if (DateUtil.isCellDateFormatted(cell)) {
return cell.getDateCellValue();
}
break;
default:
break;
}
return null;
}
示例11: convertToDate
import org.apache.commons.lang.time.DateUtils; //導入方法依賴的package包/類
public static Date convertToDate(String dateAsString, String format) {
Date answer = null;
try {
answer = DateUtils.parseDate(dateAsString, new String[] { format });
} catch (ParseException e) {
logger.error("Parsing date '%s' failed", dateAsString, e);
}
return answer;
}
示例12: deserialize
import org.apache.commons.lang.time.DateUtils; //導入方法依賴的package包/類
@Override
public Date deserialize(JsonParser arg0, DeserializationContext arg1)
throws IOException, JsonProcessingException {
if (JsonToken.VALUE_STRING.equals(arg0.getCurrentToken())) {
try {
return DateUtils.parseDate(arg0.getText(), pattern);
} catch (ParseException e) {
e.printStackTrace();
}
}
return null;
}
示例13: getTime
import org.apache.commons.lang.time.DateUtils; //導入方法依賴的package包/類
private long getTime(String date, String url) {
long time = -1;
try {
time = HttpDateFormat.toLong(date);
} catch (ParseException e) {
// try to parse it as date in alternative format
try {
Date parsedDate = DateUtils.parseDate(date, new String[] {
"EEE MMM dd HH:mm:ss yyyy", "EEE MMM dd HH:mm:ss yyyy zzz",
"EEE MMM dd HH:mm:ss zzz yyyy", "EEE, MMM dd HH:mm:ss yyyy zzz",
"EEE, dd MMM yyyy HH:mm:ss zzz", "EEE,dd MMM yyyy HH:mm:ss zzz",
"EEE, dd MMM yyyy HH:mm:sszzz", "EEE, dd MMM yyyy HH:mm:ss",
"EEE, dd-MMM-yy HH:mm:ss zzz", "yyyy/MM/dd HH:mm:ss.SSS zzz",
"yyyy/MM/dd HH:mm:ss.SSS", "yyyy/MM/dd HH:mm:ss zzz", "yyyy/MM/dd",
"yyyy.MM.dd HH:mm:ss", "yyyy-MM-dd HH:mm",
"MMM dd yyyy HH:mm:ss. zzz", "MMM dd yyyy HH:mm:ss zzz",
"dd.MM.yyyy HH:mm:ss zzz", "dd MM yyyy HH:mm:ss zzz",
"dd.MM.yyyy; HH:mm:ss", "dd.MM.yyyy HH:mm:ss", "dd.MM.yyyy zzz",
"yyyy-MM-dd'T'HH:mm:ss'Z'" });
time = parsedDate.getTime();
// if (LOG.isWarnEnabled()) {
// LOG.warn(url + ": parsed date: " + date +" to:"+time);
// }
} catch (Exception e2) {
if (LOG.isWarnEnabled()) {
LOG.warn(url + ": can't parse erroneous date: " + date);
}
}
}
return time;
}
示例14: initTestData
import org.apache.commons.lang.time.DateUtils; //導入方法依賴的package包/類
@Before
public void initTestData() throws ParseException {
executedScript1 = new ExecutedScript(new Script("1_script1.sql", 10L, "xxx"),
DateUtils.parseDate("20/05/2008 10:20:00", new String[]{"dd/MM/yyyy hh:mm:ss"}), true);
executedScript2 = new ExecutedScript(new Script("script2.sql", 20L, "yyy"),
DateUtils.parseDate("20/05/2008 10:25:00", new String[]{"dd/MM/yyyy hh:mm:ss"}), false);
}
示例15: parseDate
import org.apache.commons.lang.time.DateUtils; //導入方法依賴的package包/類
/**
* 文字列を日付に変換します.
* @param value 日付文字列
* @return 変換した日付. 変換不可の場合はnullを返します.
*/
public Date parseDate(String value) {
Date result = null;
// CHECKSTYLE:OFF
try {
result = DateUtils.parseDate(value, new String[] {FORMAT_DATE});
} catch (ParseException pe) {
// 変換不可の場合はnullを返します.
}
// CHECKSTYLE:ON
return result;
}