我想将日期转换为“ 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)?我在日历实例中也有日期。
答案 0 :(得分:0)
在 SimpleDateFormat
中使用Locale.getDefault() val formatter = SimpleDateFormat("yyyy-MM-dd", Locale.getDefault())