【问题标题】:Convert String to date format with contains characters month将字符串转换为包含字符月份的日期格式
【发布时间】:2013-10-09 03:17:16
【问题描述】:

早安,

如果我的标题和问题不正确,请纠正我。

通常我只是将字符串转换为数字格式,例如:

mm/dd/yyyy to yyyy-mm-dd as 01/02/2000 to 2000-02-01

或任何其他样式/模式。

我在想是否可以将其转换为包含字符月份的日期格式,例如:

mm/dd/yyyy to dd-MMM-yyyy as 10/09/2013 to 09-Oct-2013

哪个月份不再以数字形式显示,而是以字母形式显示。

我在 Java 中工作,Struts 框架。

请多多指教。

【问题讨论】:

标签: java string date struts


【解决方案1】:

希望这会有所帮助。您可以选择多种模式,可以在下面的链接中找到。这是一个如何使用它的示例

Multiple patterns can be found here

 final String OLD_FORMAT = "dd/MM/yyyy";

 final String NEW_FORMAT = "yyyy/MMM/dd";

 // August 12, 2010
 String oldDateString = "12/08/2010";
 String newDateString;

 SimpleDateFormat sdf = new SimpleDateFormat(OLD_FORMAT);
 Date d = sdf.parse(oldDateString);
 sdf.applyPattern(NEW_FORMAT);
 newDateString = sdf.format(d);

`

【讨论】:

  • 谢谢巴努。但我不是真的不知道我该如何输入我的输入?例如我的输入是10/09/2013。我想要的输出是09-Oct-2013
猜你喜欢
  • 1970-01-01
  • 2015-10-02
  • 1970-01-01
  • 2016-04-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多