日期格式大全
发布时间:2023-09-06 23:10:58
Java中日期格式转换
/** * 字符串转换为java.util.Date * 支持格式为 yyyy.MM.dd G 'at' hh:mm:ss z 如 '2002-1-1 AD at 22:10:59 PSD' * yy/MM/dd HH:mm:ss 如
'2002/1/1 17:55:00' * yy/MM/dd HH:mm:ss pm 如
'2002/1/1 17:55:00 pm' * yy-MM-dd HH:mm:ss 如
'2002-1-1 17:55:00' * yy-MM-dd HH:mm:ss am 如
'2002-1-1 17:55:00 am' * @param time String 字符串 * @return Date 日期 */ public static Date stringToDate(String time{ SimpleDateFormat formatter;
int tempPos=time.indexOf("AD" ; time=time.trim( ; formatter = new SimpleDateFormat ("yyyy.MM.dd G 'at' hh:mm:ss z"; if(tempPos>-1{
time=time.substring(0,tempPos+ "公元"+time.substring(tempPos+"AD".length(;//china
formatter = new SimpleDateFormat ("yyyy.MM.dd G 'at' hh:mm:ss z"; } tempPos=time.indexOf("-"; if(tempPos>-1&&(time.indexOf(" "<0{
formatter = new SimpleDateFormat ("yyyyMMddHHmmssZ"; } else if((time.indexOf("/">-1 &&(time.indexOf(" ">-1{
日期格式大全