---
title: "Calendar获取时间的月和日"
author: "zc4530"
date: "2007-03-24T09:39:13Z"
tags: []
slug: "calendar"
draft: false
lastmod: "2007-03-24T09:39:13Z"
id: 65141
url: "https://zc4530.iteye.com/blog/65141"
---

java 代码

 

01. Calendar cal = Calendar.getInstance();
02. //当前年
03. int year = cal.get(Calendar.YEAR);
04. //当前月
05. int month = (cal.get(Calendar.MONTH))+1;
06. //当前月的第几天：即当前日
07. int day\_of\_month = cal.get(Calendar.DAY\_OF\_MONTH);
08. //当前时：HOUR\_OF\_DAY-24小时制；HOUR-12小时制
09. 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);