gpt4 book ai didi

java - 如何在 ListView 项目中存储日期?

转载 作者:行者123 更新时间:2023-12-02 11:50:13 26 4
gpt4 key购买 nike

所以我想添加 ListView 中每个项目输入的日期。问题是我不知道如何存储日期,即使项目是昨天或一周前输入的,日期也会不断更新到当天。

这是日期代码

   Calendar cal = Calendar.getInstance();
SimpleDateFormat month_date = new SimpleDateFormat("dd" + " MMM");
String month_name = month_date.format(cal.getTime());

这是在 ListView 项中输入日期的代码

  while ((iterator2.hasNext() )) {
String add = iterator2.next();
conCat2.add("Added : " + add + " "+ month_name);


}

最佳答案

java.time

您正在使用麻烦的旧日期时间类,这些类现在已取代 java.time 类。对于旧版 Android,请参阅 ThreeTen-Backport 和 ThreeTenABP 项目。

MonthDay

使用 MonthDay 类来表示没有年份的日期。请注意,与遗留类不同,java.time 使用相同的月份编号,1-12 表示一月到十二月。

MonthDay md = MonthDay.of( 1 , 23 ) ;

或者,使用 Month 枚举。

MonthDay md = MonthDay.of( Month.JANUARY , 23 ) ;

本地日期

如果您指的是包含年份的完整日期,请使用LocalDate

LocalDate ld = LocalDate.of( 2017 , 1 , 23 ) ;

关于java - 如何在 ListView 项目中存储日期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47928534/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com