【发布时间】:2019-08-17 21:13:13
【问题描述】:
我真的用过这个
Calendar calendar = Calendar.getInstance();
final String currentDate =
DateFormat.getDateInstance(DateFormat.FULL).format(calendar.getTime());
结果 = 2019 年 3 月 27 日,星期三
我需要这个:27032019 没有 , / 或 . 仅限XXXXXXXX
谢谢你
【问题讨论】:
-
研究 SimpleDateFormat。但我认为这应该可行: SimpleDateFormat format = new SimpleDateFormat("ddMMyyy")
-
尝试使用新的 java 8 time api 的 LocalDate。日期现已过时。
-
顺便考虑扔掉长期过时且臭名昭著的麻烦
DateFormat和朋友,并将ThreeTenABP添加到您的Android项目中,以便使用java.time,现代Java日期和时间API .与它一起工作要好得多。LocalDate.now(yourTimeZone).format(DateTimeFormatter.ofPattern("ddMMuuuu")). -
您需要
27032019做什么?它不易被人类阅读,不推荐用于序列化(后者使用ISO 8601 格式:2019-03-27)。
标签: java android calendar format