SimpleDateFormat sdf1 = new SimpleDateFormat(realDateFormat, Locale.ENGLISH);
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
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.
楼主有必要这么复杂吗??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
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
只是得到日期我当然知道怎么做,我的问题就是SimpleDateFormat.parse()的用法,只有SimpleDateFormat sdf1 = new SimpleDateFormat(realDateFormat, Locale.ENGLISH);解决了问题
SimpleDateFormat.parse() is called with a date string ending with "GMT".
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
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
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