怎么样将这样的字符串“Jan 10 19:19:28 2012”转换为date格式。我这样转换有问题,但不知道格式哪里错了:String date = "Jan 10 19:19:28 2012";
SimpleDateFormat formatter = new SimpleDateFormat("MMM dd HH:mm:ss yyyy");
long currdate = formatter.parse(date).getTime();
SimpleDateFormat formatter = new SimpleDateFormat("MMM dd HH:mm:ss yyyy");
long currdate = formatter.parse(date).getTime();
public static void main(String[] args) {
String date = "Jan 10 19:19:28 2012";
long d = Date.parse(date);
System.out.println(d);
SimpleDateFormat formatter = new SimpleDateFormat(
"yyyy MM dd HH:mm:SS");
String currdate;
currdate = formatter.format(d);
System.out.println(currdate);
}
public class TestDate {
public static void main(String[] args) throws Exception
{
String date = "05 02 12:12:12 2012";
SimpleDateFormat formatter = new SimpleDateFormat("MM dd HH:mm:ss yyyy");
long currdate = formatter.parse(date).getTime(); System.out.println(currdate);
}
}
前后格式要对应,兄弟
import java.text.SimpleDateFormat;
import java.util.Date;public class Test {
public static void main(String[] aa) {
SimpleDateFormat dateformat1 = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss E");
String a1 = dateformat1.format(new Date());
System.out.println("时间2:" + a1);
System.out.println(new Date().getYear() + 1900); SimpleDateFormat dateformat2 = new SimpleDateFormat(
"yyyy年MM月dd日 HH时mm分ss秒 E ");
String a2 = dateformat2.format(new Date());
System.out.println("时间2:" + a2);
}
}
LZ自己看着用吧
public class TestDate {
public static void main(String[] args) throws Exception
{
String str="Jan 02 12:12:12 2012";
SimpleDateFormat formatter = new SimpleDateFormat("MMM dd HH:mm:ss yyyy",Locale.ENGLISH);
Date ts = formatter.parse(str);
SimpleDateFormat formatter1 = new SimpleDateFormat("yyyy MM HH:mm:SS");
System.out.print(formatter1.format(ts));
}
}