唉,也没人说啊,算了,还是我分享一下吧,下面就是我找了N久 才觅得的方法(这个不常用) public static String geTime(String dateString) { dateString=replace(dateString, "GMT+00:00", "CST"); Date f = new Date(); f.parse(dateString); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); return format.format(f); } public static String replace(String strSource, String strFrom, String strTo) { if (strSource == null) { return null; } int i = 0; if ((i = strSource.indexOf(strFrom, i)) >= 0) { char[] cSrc = strSource.toCharArray(); char[] cTo = strTo.toCharArray(); int len = strFrom.length(); StringBuffer buf = new StringBuffer(cSrc.length); buf.append(cSrc, 0, i).append(cTo); i += len; int j = i; while ((i = strSource.indexOf(strFrom, i)) > 0) { buf.append(cSrc, j, i - j).append(cTo); i += len; j = i; } buf.append(cSrc, j, cSrc.length - j); return buf.toString(); } return strSource; }
貌似不用这么麻烦吧。Thu Nov 10 13:57:12 GMT+00:00 2011 这种格式的时间可以直接用new Date().parse()直接转成Date类型,然后使用SimpleDateFormat直接进行格式化的
同上,楼主可以看一下JavaAPI,这样的方法java本身其实已经提供好了
一楼的有太多没用方法,(*^__^*) 嘻嘻……,直接geTime方法就行了吧
public static String geTime(String dateString) { dateString=replace(dateString, "GMT+00:00", "CST"); Date f = new Date(); f.parse(dateString); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); return format.format(f); } 这样就ok了
public static String geTime(String dateString)
{
dateString=replace(dateString, "GMT+00:00", "CST");
Date f = new Date();
f.parse(dateString);
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return format.format(f);
}
public static String replace(String strSource, String strFrom, String strTo) {
if (strSource == null) {
return null;
}
int i = 0;
if ((i = strSource.indexOf(strFrom, i)) >= 0) {
char[] cSrc = strSource.toCharArray();
char[] cTo = strTo.toCharArray();
int len = strFrom.length();
StringBuffer buf = new StringBuffer(cSrc.length);
buf.append(cSrc, 0, i).append(cTo);
i += len;
int j = i;
while ((i = strSource.indexOf(strFrom, i)) > 0) {
buf.append(cSrc, j, i - j).append(cTo);
i += len;
j = i;
}
buf.append(cSrc, j, cSrc.length - j);
return buf.toString();
}
return strSource;
}
这种格式的时间可以直接用new Date().parse()直接转成Date类型,然后使用SimpleDateFormat直接进行格式化的
{
dateString=replace(dateString, "GMT+00:00", "CST");
Date f = new Date();
f.parse(dateString);
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return format.format(f);
}
这样就ok了