SimpleDateFormat bartDateFormat = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss");
改成:
SimpleDateFormat bartDateFormat =
new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss",Locale.ENGLISH);
改成:
SimpleDateFormat bartDateFormat =
new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss",Locale.ENGLISH);
解决方案 »
- equals问题
- 大家讨论一下中文变量名的优劣
- paintComonent java
- 大家给我帮我写个例子 用java语言编写插入大对象到oracle!高分
- java连接数据库表时对其插入所遇到的困难,请各位高手伸出你们的帮助之手!
- 请问想在JTextPane中搜索关键字,并将它高亮度化如何实现?
- 如何把java程序转换到C下?
- 关于JBuilder和Sun Java!!!
- 关于jdk中文版的一点想法,请大家看看
- 写sql进数据库(DB2)怎样实现自动插入(表的主键为String)
- jdk里面有没有直接判断一个数是偶数还是奇数的方法
- 我把.wav文件转换成了byte[],java有什么api以byte[]做参数来播放音乐
import java.util.Date;
import java.util.Locale
import java.text.DateFormat;
import java.text.ParseException;public class DateExample { public static void main(String[] args) {
// Create a date formatter that can parse dates of
// the form MM-dd-yyyy.
SimpleDateFormat bartDateFormat = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss",Locale.ENGLISH); // Create a string containing a text date to be parsed.
String dateStringToParse = "2004-11-6 23:14:31"; try {
// Parse the text version of the date.
// We have to perform the parse method in a
// try-catch construct in case dateStringToParse
// does not contain a date in the format we are expecting.
Date date = bartDateFormat.parse(dateStringToParse); // Now send the parsed date as a long value
// to the system output.
System.out.println(date.getTime());
}
catch (Exception ex) {
System.out.println(ex.getMessage());
}
} -------------------------------------------
编译通过,执行出错,返回
Unparseable date: "2004-11-6 23:14:31"
SimpleDateFormat bartDateFormat = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss",Locale.ENGLISH);
改成:
SimpleDateFormat bartDateFormat = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss", Locale.ENGLISH);
就行了。只要你指定的格式和dateStringToParse 里的格式对应就可以转换了