在Android中,当您使用"Mon Dec 03 00:13:21 GMT+05:30 2018"
进行转换时,所有Date对象都以这种日期格式SimpleDateFormat
给出。
是否有可能在Android中以"dd-mm-yyyy"
格式获取Date对象?
答案 0 :(得分:1)
您可以在SimpleDateFormat上设置模式并设置日期格式:
new SimpleDateFormat("dd-mm-yyyy").format(new Date());
答案 1 :(得分:1)
您可以将Strings
转换为Dates
,如下所示:
String pattern = "dd-mm-yyyy";
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
String strDate = simpleDateFormat.format(new Date());//firstly get formatted str
Date newDate = simpleDateFormat.parse(strDate);//then get date object with wanted format