SimpleDateFormat format1 = new SimpleDateFormat(
                "yyyy.MM.dd G 'at' HH:mm:ss z");
    Date d1=null;
    try{
      d1 = format1.parse("2001.07.04 AD at 12:08:56 PDT");
       System.out.println(d1.toString());
    }
    catch(ParseException pe){
      pe.printStackTrace();
    } error:  java.text.ParseException: Unparseable date: "2001.07.04 AD at 12:08:56 PDT" at java.text.DateFormat.parse(DateFormat.java:335)
   PLS HELP,3KS!

解决方案 »

  1.   

    java.text.DateFormat df = new java.text.SimpleDateFormat("yyyy.MM.dd G 'at' HH:mm:ss z",Locale.US);
    这样构建。因为你所指定的格式化方式是美国的,而你在初始化DateFormat的时候默认的使用的中国本地的一些格式偏好。
      

  2.   

    SimpleDateFormat format1 = new SimpleDateFormat(
                    "yyyy.MM.dd G 'at' HH:mm:ss z");改为 --〉
    SimpleDateFormat format1 = new SimpleDateFormat(
    "yyyy.MM.dd G 'at' HH:mm:ss z", Locale.US);
      

  3.   

    SimpleDateFormat format1 = new SimpleDateFormat(
    "yyyy.MM.dd G 'at' HH:mm:ss z");
    Date d1 = null;
    try {
    String aaa = format1.format(new Date());
    d1 = format1.parse("2006.10.24 西暦 at 10:28:09 CST");
    System.out.println(d1.toString());
    } catch (Exception pe) {
    pe.printStackTrace();
    }
    刚才调试了一下
    这样就没有问题
    呵呵,我的是日文的操作系统
    和操作系统有关
      

  4.   

    多谢各位高手的帮助。程序已经通过。
       只是有个小疑问,从哪儿知道我指定的日期格式是美国的,而不是我们本地的呢。有没有这样的格式啊:SimpleDateFormat format1 = new SimpleDateFormat(
    "YYYY-MM-DD HH24:MI:SS");
                 String str="2006-07-03 12:00:00";
                 Date d1=format1.foramt(str);
        谢谢!
      

  5.   

    JDK1.4 manual:  
    Examples
    The following examples show how date and time patterns are interpreted in the U.S. locale. The given date and time are 2001-07-04 12:08:56 local time in the U.S. Pacific Time time zone. 
    Date and Time Pattern  Result  
    "yyyy.MM.dd G 'at' HH:mm:ss z"  2001.07.04 AD at 12:08:56 PDT  
    "EEE, MMM d, ''yy"  Wed, Jul 4, '01  
    "h:mm a"  12:08 PM  
    "hh 'o''clock' a, zzzz"  12 o'clock PM, Pacific Daylight Time  
    "K:mm a, z"  0:08 PM, PDT  
    "yyyyy.MMMMM.dd GGG hh:mm aaa"  02001.July.04 AD 12:08 PM  
    "EEE, d MMM yyyy HH:mm:ss Z"  Wed, 4 Jul 2001 12:08:56 -0700  
    "yyMMddHHmmssZ"  010704120856-0700