更新时间:2023-02-26 20:07:56
可能的解释:
Sep
作为月份名称 t
是错误的类型(例如 java.sql.Date
而不是 java.util.Date
或其他一些类型)或未声明。Sep
as a month namet
is the wrong type (e.g. java.sql.Date
instead of java.util.Date
, or some other type altogether), or is not declared.您应该包括你的问题的异常的细节,以弄清楚它是什么,但这里是一个工作示例,使用基本上你自己的代码,添加了一个特定的 Locale
。
You should include details of the exception in your question to figure out which it is, but here's a working example using basically your own code, with the addition of a specific Locale
.
SimpleDateFormat ft = new SimpleDateFormat("MMM dd, yyyy hh:mm:ss a", Locale.US);
java.util.Date t=ft.parse("Sep 16, 2015 10:34:23 AM");
ft.applyPattern("MM.dd");
System.out.println(ft.format(t));
输出:
09.16