SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd"); // 规定日期格式
String now = formatter.format(Date.parse("Mon Jan 20 00:00:00 CST 1986"));System.out.println(now);
这种方法格式化日期现在不推荐使用,请问有没有更好的解决方法(不通过获取日期字符串判断年月日的方法)!
String now = formatter.format(Date.parse("Mon Jan 20 00:00:00 CST 1986"));System.out.println(now);
这种方法格式化日期现在不推荐使用,请问有没有更好的解决方法(不通过获取日期字符串判断年月日的方法)!
SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println(dateformat.format(date));一直这么格式化时间来着。没有不推荐啊。你是想说(Date.parse("Mon Jan 20 00:00:00 CST 1986"))这句么?
Date.parse("Mon Jan 20 00:00:00 CST 1986")
不知道还有什么方法,学习!
在eclipse运行的时候parse被划上了横线
Date date = dateformat.parse("Mon Jan 20 00:00:00 CST 1986");
SimpleDateFormat simpledateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println(simpledateformat.format(date));你是想说字符串转日期么?如上
parse(String s)已过时。 从 JDK 1.1 开始,由 DateFormat.parse(String s) 取代。
java.text.ParseException: Unparseable date: "Mon Jan 20 00:00:00 CST 1986"确实包异常了
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd"); // 规定日期格式
Date date = formatter.parse("Mon Jan 20 00:00:00 CST 1986"); //直接转换
String now = formatter.format(date);
大概就是这样,你可以查看一下JDK文档
SimpleDateFormat继承于java.text.DateFormat的parse方法,具体忘了
呵呵。无法转换的日期嘛。自己在catch里处理咯。不可能啥字符串也可以用DateFormat做parse
好了。该结贴了
不用toString(),可以直接将Date格式化呀,Date变量是指一个Date类型的对象吧,
那二楼说的就是这个意思!