com.aliyun.datahub.client.util.DateUtils Maven / Gradle / Ivy
package com.aliyun.datahub.client.util;
import org.apache.commons.lang3.StringUtils;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class DateUtils {
public static Date parseDateNoTime(String sDate) throws ParseException {
DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
if (sDate != null && sDate.length() >= "yyyyMMdd".length()) {
if (!StringUtils.isNumeric(sDate)) {
throw new ParseException("not all digit", 0);
} else {
return dateFormat.parse(sDate);
}
} else {
throw new ParseException("length too little", 0);
}
}
public static Date parseDateNoTime(String sDate, String format) throws ParseException {
if (StringUtils.isBlank(format)) {
throw new ParseException("null format.", 0);
} else {
DateFormat dateFormat = new SimpleDateFormat(format);
if (sDate != null && sDate.length() >= format.length()) {
return dateFormat.parse(sDate);
} else {
throw new ParseException("length too little.", 0);
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy