如何将日期Nov 8, 2005 11:33:15 AM 转换成2005-11-8 11:33:15

Abingdz 2005-11-08 11:53:37
如何将日期Nov 8, 2005 11:33:15 AM 转换成2005-11-8 11:33:15
...全文
192 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
gogon 2005-11-08
  • 打赏
  • 举报
回复
看一下DateFormat
先df.parse();然后 df.format();
loulou82 2005-11-08
  • 打赏
  • 举报
回复
public static String toDateString(Date date, String toFormat)
{
GregorianCalendar gc = new GregorianCalendar();
SimpleDateFormat df = new SimpleDateFormat(toFormat);
df.setTimeZone(gc.getTimeZone());
String toDateString = df.format(date);
return toDateString;
}
bright_wish 2005-11-08
  • 打赏
  • 举报
回复
String str="Nov 8, 2005 11:33:15 AM";
DateFormat df = new SimpleDateFormat("MMM d, yyyy hh:mm:ss a", Locale.ENGLISH);
DateFormat style = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss", Locale.ENGLISH);
String result=df.format(new Date());
System.out.println(style.format( df.parse(str)));

把AM写为PM看看 !!
DateFormat style = new SimpleDateFormat("yyyy-MM-dd k:mm:ss",
eureka0891 2005-11-08
  • 打赏
  • 举报
回复

String str="Nov 8, 2005 11:33:15 AM";
DateFormat df = new SimpleDateFormat("MMM d, yyyy hh:mm:ss a", Locale.ENGLISH);
DateFormat style = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss", Locale.ENGLISH);
String result=df.format(new Date());
System.out.println(style.format( df.parse(str)));
my4989 2005-11-08
  • 打赏
  • 举报
回复
测试代码:
Date d = new Date();
System.out.println(d);

SimpleDateFormat sdf = new SimpleDateFormat();
System.out.println( sdf.format(d));

测试结果:
Tue Nov 08 13:26:37 CST 2005
05/11/08 13:26
bixuehui 2005-11-08
  • 打赏
  • 举报
回复
Date da=new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println(sdf.format(da));

62,624

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧