calendar.clear()
时间: 2023-07-14 09:03:27 浏览: 54
`calendar.clear()` 是 Calendar 类的一个方法,用于清除当前 Calendar 对象的所有字段值,将其重置为初始状态。调用该方法后,Calendar 对象的所有字段(如年、月、日、小时、分钟等)都被设置为默认值,通常是0或者对应字段的最小值。
以下是使用 `clear()` 方法的示例:
```java
Calendar calendar = Calendar.getInstance();
System.out.println("初始日期和时间:" + calendar.getTime());
calendar.clear();
System.out.println("清除后的日期和时间:" + calendar.getTime());
```
输出结果可能如下所示:
```
初始日期和时间:Wed Dec 08 16:01:19 CST 2021
清除后的日期和时间:Thu Jan 01 00:00:00 CST 1970
```
在上述示例中,首先获取了当前日期和时间的 Calendar 对象,然后调用 `clear()` 方法清除了所有字段的值,最后再次输出 Calendar 对象的日期和时间,可以看到它被重置为默认值。
相关问题
下面这一段代码的功能是什么void calendar_test(void) { u8 key_temp=0; lcd1602_init(); ds1302_init(); ds18b20_init(); time0_init();//定时器设置 while(1) { key_temp=key_scan(0); if(key_temp==KEY1_PRESS)//模式设置 { g_calendar.mode++; if(g_calendar.mode==3) g_calendar.mode=1; g_calendar.setok=0; g_calendar.time_choice=0; if(g_calendar.mode==2) { lcd1602_clear(); lcd1602_show_string(0,0,alarm_switch_str); } beep_alarm(200,20); } else if(key_temp==KEY2_PRESS)/进入设置模式时,对应位选择 { g_calendar.time_choice++; if(g_calendar.time_choice==7) g_calendar.time_choice=0; beep_alarm(200,20); } else if(key_temp==KEY3_PRESS)//进入设置模式时,对应数据加操作 { g_calendar.add=1; beep_alarm(200,20); } else if(key_temp==KEY4_PRESS)//设置完成,恢复正常显示模式 { g_calendar.setok=1; g_calendar.time_choice=0; g_calendar.mode=0; calendar_save_set_time(); beep_alarm(200,20); } if(g_calendar.mode==1)//模拟光标闪烁 { if(g_calendar.time_choice<3) lcd1602_show_string(7-g_calendar.time_choice*3,1," "); else if(g_calendar.time_choice>=3&&g_calendar.time_choice<4) lcd1602_show_string(14,0," "); else if(g_calendar.time_choice>=4&&g_calendar.time_choice<7) lcd1602_show_string(21-g_calendar.time_choice*3,0," "); } else if(g_calendar.mode==2)//模拟光标闪烁 { if(g_calendar.time_choice<2) lcd1602_show_string(4-g_calendar.time_choice*3,1," "); else if(g_calendar.time_choice==2) lcd1602_show_string(9,0," "); else if(g_calendar.time_choice==3) lcd1602_show_string(4,1," "); } calendar_set_time(); calendar_set_alarm(); calendar_show(); alarm_compareproc(); } }
这段代码是一个日历闹钟程序的主函数,主要功能如下:
1. 初始化LCD1602,DS1302,DS18B20以及定时器。
2. 循环执行以下操作:
a. 通过按键扫描获取按键值。
b. 根据按键值进行相应的操作,如进入/退出模式设置,选择需要设置的时间/日期,设置时间/日期,保存设置等。
c. 根据当前模式模拟光标闪烁,以提示用户当前选择的是哪个时间/日期。
d. 显示时间/日期以及闹钟开关状态。
e. 比较当前时间和闹钟设置的时间,若匹配则触发闹钟响铃。
private void loadData() { List<AccountData> lst=accountDataDao.findAll(); today.clear(); Date date=new Date(); SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy年MM月dd日 HH:mm"); String nowtime=simpleDateFormat.format(date); Calendar calendar = Calendar.getInstance(); int year = calendar.get(Calendar.YEAR); int month = calendar.get(Calendar.MONTH)+1; int day = calendar.get(Calendar.DAY_OF_MONTH); //收入1 支出0 float in_day=accountDataDao.qaskMoney(1,year,month,day); float out_day=accountDataDao.qaskMoney(0,year,month,day); float in_sum=accountDataDao.qaskMoneySum(1); float out_sum=accountDataDao.qaskMoneySum(0); today=accountDataDao.qask_by_ymd(day,month,year); mainLsAdapter=new MainLsAdapter(this,today); today_ls.setAdapter(mainLsAdapter); for(AccountData tt:today) System.out.println(tt); tv_day_in.setText("+¥"+in_day+"元"); tv_day_out.setText("-¥"+out_day+"元"); tv_month_in.setText("¥"+in_sum+"元"); tv_month_out.setText("¥"+out_sum+"元"); }
这段代码是一个加载数据的方法,大概的流程如下:
1. 从数据库中获取所有的账单数据并存储在一个 List<AccountData> lst 中。
2. 清空 today 集合,并获取当前日期和时间的字符串形式。
3. 获取当前的年份、月份、日期,并且分别计算当天的收入和支出总金额,以及全部时间内的总收入和支出金额。
4. 从数据库中获取当天的账单数据,并且将其存储在 today 集合中。
5. 创建一个 MainLsAdapter 适配器对象,并设置 today_ls 列表视图的适配器为该适配器。
6. 打印 today 集合中的所有账单数据。
7. 将当天的收入和支出总金额显示在 tv_day_in 和 tv_day_out 文本视图中,将全部时间内的总收入和支出金额显示在 tv_month_in 和 tv_month_out 文本视图中。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)