这是我第一篇博客,由于本人技术有限,可能会出现一些谬误,请多指正!
最近我在做的是关于某通讯运营商的漏洞管理平台,该平台采用前端采用ext框架,在页面中选择时期Date类型,传到后台的时候变成了UTC格式的String类型。网上的关于String转Date的方法都是YYYY/MM/DD形式的,我就自己写了个UTC形式的String转换为Date形式的方法,供大家参考。
//将UTC格式的日期字符串转换成date型
public Date Convertdate( String UTCstr) throws ParseException
{
String dateString="";
Map<String,String> map = new HashMap<String,String>();
map.put("Jan", "01");
map.put("Feb", "02");
map.put("Mar", "03");
map.put("Apr", "04");
map.put("May", "05");
map.put("Jan", "06");
map.put("Jul", "07");
map.put("Aug", "08");
map.put("Sep", "09");
map.put("Oct", "10");
map.put("Nov", "11");
map.put("Dec", "12");
String[] str=UTCstr.split(" ");
//"yyyy-MM-dd hh:mm:ss"
dateString=str[6]+"-"+map.get(str[1])+"-"+str[2]+" "+str[3];
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
Date myDate = sdf.parse(dateString);
return myDate;
}
本文介绍了一种将UTC格式的日期字符串转换为Date类型的实用方法。通过解析UTC字符串中的月份名称并将其转换为对应的数字,再重组字符串为标准日期格式,最终使用SimpleDateFormat完成转换。
976

被折叠的 条评论
为什么被折叠?



