作者热门文章
- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
由于这些日期的格式,我无法对日期进行排序。
我得到日期:
final Calendar c = Calendar.getInstance();
mYear = c.get(Calendar.YEAR);
mMonth = c.get(Calendar.MONTH);
mDay = c.get(Calendar.DAY_OF_MONTH);
我用这些值构建了一个字符串。
dateRappDB = (new StringBuilder()
.append(mYear).append(".")
.append(mMonth + 1).append(".")
.append(mDay).append(" ")).toString();
问题是,如果月份是例如二月,则 mMonth 值为 2。因此,像十月 (10) 这样的月份的日期在我的列表之前。
我需要的是月份和日期的格式类似于 MM 和 dd。但在我的情况下,我不知道该怎么做。
编辑:
我通过使用上述 DateFormat 解决了这个问题。
我替换了这个:
dateRappDB = (new StringBuilder()
.append(mYear).append(".")
.append(mMonth + 1).append(".")
.append(mDay).append(" ")).toString();
通过这个:
Date date = new Date(mYear - 1900, mMonth, mDay);
dateFacDB = DateFormat.format("yyyy.MM.dd", date).toString();
而且它有效。感谢大家的帮助:)
最佳答案
这是一个将日期转换为字符串的简单方法:
SimpleDateFormat simpleDate = new SimpleDateFormat("dd/MM/yyyy");
String strDt = simpleDate.format(dt);
关于java - 安卓 : date format in a String,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7281633/
我是一名优秀的程序员,十分优秀!