ITeye博客

Calendar获取时间的月和日

zc4530 · 2007-03-24 09:39 · JAVA · Markdown

java 代码

 

  1. Calendar cal = Calendar.getInstance();
  2. //当前年
  3. int year = cal.get(Calendar.YEAR);
  4. //当前月
  5. int month = (cal.get(Calendar.MONTH))+1;
  6. //当前月的第几天:即当前日
  7. int day_of_month = cal.get(Calendar.DAY_OF_MONTH);
  8. //当前时:HOUR_OF_DAY-24小时制;HOUR-12小时制
  9. int hour = cal.get(Calendar.HOUR_OF_DAY);
  10. //当前分
  11. int minute = cal.get(Calendar.MINUTE);
  12. //当前秒
  13. int second = cal.get(Calendar.SECOND);
  14. //0-上午;1-下午
  15. int ampm = cal.get(Calendar.AM_PM);
  16. //当前年的第几周
  17. int week_of_year = cal.get(Calendar.WEEK_OF_YEAR);
  18. //当前月的第几周
  19. int week_of_month = cal.get(Calendar.WEEK_OF_MONTH);
  20. //当前年的第几天
  21. int day_of_year = cal.get(Calendar.DAY_OF_YEAR);

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。