Android /java时间格式?
我有时间作为“2011-12-03 12:00:19”如何将其转换为“Fri 2 December 2011”,我知道这个 http://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html ,但给了我错误:
Exception in thread "main" java.lang.IllegalArgumentException: Cannot format given Object as a Date
at java.text.DateFormat.format(Unknown Source)
at java.text.Format.format(Unknown Source)
at com.timestamp.NewTimeStamp.<init>(NewTimeStamp.java:21)
at com.timestamp.NewTimeStamp.main(NewTimeStamp.java:35)
我的代码是::
String mytime ="2011-12-03 12:00:19";
String pattern = "EEE d MMMMM yyyy";
SimpleDateFormat dateFormat = new SimpleDateFormat(pattern);
Date date = new Date(mytime);
String time = dateFormat.format(date);
System.out.println("=== > " + time);
I have time as a "2011-12-03 12:00:19" how to convert it in "Fri 2 December 2011 " ,I know this http://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html ,But gives me Error:
Exception in thread "main" java.lang.IllegalArgumentException: Cannot format given Object as a Date
at java.text.DateFormat.format(Unknown Source)
at java.text.Format.format(Unknown Source)
at com.timestamp.NewTimeStamp.<init>(NewTimeStamp.java:21)
at com.timestamp.NewTimeStamp.main(NewTimeStamp.java:35)
My code is ::
String mytime ="2011-12-03 12:00:19";
String pattern = "EEE d MMMMM yyyy";
SimpleDateFormat dateFormat = new SimpleDateFormat(pattern);
Date date = new Date(mytime);
String time = dateFormat.format(date);
System.out.println("=== > " + time);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将您的输入转换为
日期
,然后格式化。输出:
Convert your input to
Date
and then format.Output: