string转date工具类Java
时间: 2023-10-08 10:09:26 浏览: 117
你可以使用下面这个Java类中的String2Date方法将字符串转换为日期:
```java
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.dubbo.common.utils.StringUtils;
public class DateUtils {
private static SimpleDateFormat sd = new SimpleDateFormat();
private static Logger logger = LoggerFactory.getLogger(DateUtils.class);
public static Date String2Date(String time ,String pattern) {
sd.applyPattern(pattern);
if(StringUtils.isNotEmpty(time)) {
try {
return sd.parse(time);
} catch (ParseException e) {
logger.error("convert Date error the time is " + time + "[" + e.getMessage() + "]");
}
}
return null;
}
}
```
阅读全文
相关推荐














