日期:2014-05-20  浏览次数:20771 次

时间处理问题……急啊,请各位大虾指点
怎么样将这样的字符串“Jan 10 19:19:28 2012”转换为date格式。

我这样转换有问题,但不知道格式哪里错了:
Java code

String date = "Jan 10 19:19:28 2012";
SimpleDateFormat formatter = new SimpleDateFormat("MMM dd HH:mm:ss yyyy");
long currdate = formatter.parse(date).getTime();



------解决方案--------------------
Java code

    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);
            
    }

------解决方案--------------------
Java code

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);
        
    }
}

------解决方案--------------------
Java code

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);
    }
}

------解决方案--------------------
Java code

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));
    }
}

------解决方案--------------------
探讨

说实话我是google加API做出来的。。。