哦,Date thisDate = f1.parse(new Date().toString(), pos);
应该是 Date thisDate = sdf1.parse(new Date().toString(), pos);不过结果还是不对,why

解决方案 »

  1.   

    SimpleDateFormat sdf1 = new SimpleDateFormat(realDateFormat, Locale.ENGLISH);
      

  2.   

    import java.util.*;
    import java.text.*;public class testDate{
      private static final String realDateFormat = "EEE MMM dd HH:mm:ss z yyyy";
      public static void  main(String[] args){
        SimpleDateFormat sdf1 = new SimpleDateFormat(realDateFormat);
        ParsePosition pos = new ParsePosition(0);
        Date thisDate = sdf1.parse(sdf1.format(new Date()),pos);
        System.out.println(thisDate);
      }//end main
    }//end class
      

  3.   

    A Locale object represents a specific geographical, political, or cultural region. An operation that requires a Locale to perform its task is called locale-sensitive and uses the Locale to tailor information for the user. For example, displaying a number is a locale-sensitive operation--the number should be formatted according to the customs/conventions of the user's native country, region, or culture.
      

  4.   

    楼主有必要这么复杂吗??import java.util.*;
    import java.text.*;public class testDate{
      private static final String realDateFormat = "EEE MMM dd HH:mm:ss z yyyy";
      public static void  main(String[] args){
        SimpleDateFormat sdf1 = new SimpleDateFormat(realDateFormat);
        
        String thisDate = sdf1.format(new Date());
        System.out.println(thisDate);
      }//end main
    }//end class
      

  5.   

    Parameters:
    pos - A ParsePosition object with index and error index information as described above.
    text - The date/time string to be parsed 
    Returns:
    A Date parsed from the string. In case of error, returns null. 
    Throws: 
    NullPointerException - if text or pos is null呵呵,你的pos是个null
      

  6.   

    只是得到日期我当然知道怎么做,我的问题就是SimpleDateFormat.parse()的用法,只有SimpleDateFormat sdf1 = new SimpleDateFormat(realDateFormat, Locale.ENGLISH);解决了问题
      

  7.   

    SimpleDateFormat.parse() is  called with a date string ending with "GMT".