import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
/**
* @author alone
* @date 2019/9/19
*/
public class Test {
@org.junit.Test
public void getTime() throws ParseException {
String str = "Tue Jan 01 00:00:00 CST 1980";
Date date = parse(str, "EEE MMM dd HH:mm:ss zzz yyyy", Locale.US);
System.out.println(new SimpleDateFormat("yyyy-MM-dd").format(date));
System.out.printf("%tF %<tT%n", date);
}
private Date parse(String str, String pattern, Locale locale) {
if(str == null || pattern == null) {
return null;
}
try {
return new SimpleDateFormat(pattern, locale).parse(str);
} catch (ParseException e) {
e.printStackTrace();
}
return null;
}
}
(已解决)出现字符串为“Tue Jan 01 00:00:00 CST 1980“格式的转换为时间类型或者字符串
最新推荐文章于 2023-01-05 14:48:38 发布