【发布时间】:2013-08-29 05:31:51
【问题描述】:
这是我在 scala 中的代码
var s:String ="22/08/2013"
var simpleDateFormat:SimpleDateFormat = new SimpleDateFormat("yyyy-mm-dd");
var date:Date = simpleDateFormat.parse(s);
println(date)
日期不变。 日期与 22/08/2013 相同的格式 2013/08/22 没有变化
如何在scala中将格式dd/mm/yyyy更改为yyyy/mm/dd
【问题讨论】:
-
scala 代码中最好省略分号。这是首选的风格。也不需要指定像 String 这样的常见类型。
-
@Vishal 好的,vishal 这是我的错误……感谢您的回答
-
你可能想看看日期格式化教程..docs.oracle.com/javase/tutorial/i18n/format/…
-
@Shrey thans 这对我很有帮助
-
现代评论:我建议你不要使用
SimpleDateFormat和Date。这些类设计不佳且早已过时,尤其是前者,尤其是出了名的麻烦。而是使用来自java.time, the modern Java date and time API 的LocalDate和DateTimeFormatter。
标签: scala date date-format simpledateformat