哪个语言环境(SimpleDateFormat)是“ yyyy-MM-dd”?

时间:2020-03-01 17:10:37

标签: android date simpledateformat

我想将日期转换为“ yyyy-MM-dd”。我正在使用

 val parser = SimpleDateFormat("dd-MMM-yyyy") // The original format
 val formatter = SimpleDateFormat("yyyy-MM-dd")
 val output = formatter.format(parser.parse(etDOB.text.toString()))

here所示。但是Android studio警告我使用SimpleDateFormat(String,Locale)。我应该使用哪个语言环境来输出到“ yyyy-MM-dd”?

还是有更好的方法来实现这一目标(API 21)?我在日历实例中也有日期。

1 个答案:

答案 0 :(得分:0)

SimpleDateFormat

中使用Locale.getDefault()
 val formatter = SimpleDateFormat("yyyy-MM-dd", Locale.getDefault())
相关问题