`
lysvanilla
  • 浏览: 78586 次
  • 性别: Icon_minigender_1
  • 来自: 湖南
社区版块
存档分类
最新评论

Calendar常用方法封装

阅读更多
Java代码 复制代码 收藏代码
  1. <PRE class=java name="code">package com.iwode.common;
  2. import java.text.DateFormat;
  3. import java.text.ParsePosition;
  4. import java.text.SimpleDateFormat;
  5. import java.util.Calendar;
  6. import java.util.Date;
  7. import java.util.GregorianCalendar;
  8. /**
  9. * 常用日历操作辅助类
  10. *
  11. * @author steven 2010-08-10
  12. * @email:qing.tan@iwode.com
  13. */
  14. public class CalendarUtil {
  15. private int weeks = 0;// 用来全局控制 上一周,本周,下一周的周数变化
  16. private int MaxDate; // 一月最大天数
  17. private int MaxYear; // 一年最大天数
  18. /**
  19. * 测试
  20. *
  21. * @param args
  22. */
  23. public static void main(String[] args) {
  24. CalendarUtil tt = new CalendarUtil();
  25. System.out.println("获取当天日期:" + tt.getNowTime("yyyy-MM-dd"));
  26. System.out.println("获取本周一日期:" + tt.getMondayOFWeek());
  27. System.out.println("获取本周日的日期~:" + tt.getCurrentWeekday());
  28. System.out.println("获取上周一日期:" + tt.getPreviousWeekday());
  29. System.out.println("获取上周日日期:" + tt.getPreviousWeekSunday());
  30. System.out.println("获取下周一日期:" + tt.getNextMonday());
  31. System.out.println("获取下周日日期:" + tt.getNextSunday());
  32. System.out.println("获得相应周的周六的日期:" + tt.getNowTime("yyyy-MM-dd"));
  33. System.out.println("获取本月第一天日期:" + tt.getFirstDayOfMonth());
  34. System.out.println("获取本月最后一天日期:" + tt.getDefaultDay());
  35. System.out.println("获取上月第一天日期:" + tt.getPreviousMonthFirst());
  36. System.out.println("获取上月最后一天的日期:" + tt.getPreviousMonthEnd());
  37. System.out.println("获取下月第一天日期:" + tt.getNextMonthFirst());
  38. System.out.println("获取下月最后一天日期:" + tt.getNextMonthEnd());
  39. System.out.println("获取本年的第一天日期:" + tt.getCurrentYearFirst());
  40. System.out.println("获取本年最后一天日期:" + tt.getCurrentYearEnd());
  41. System.out.println("获取去年的第一天日期:" + tt.getPreviousYearFirst());
  42. System.out.println("获取去年的最后一天日期:" + tt.getPreviousYearEnd());
  43. System.out.println("获取明年第一天日期:" + tt.getNextYearFirst());
  44. System.out.println("获取明年最后一天日期:" + tt.getNextYearEnd());
  45. System.out.println("获取本季度第一天:" + tt.getThisSeasonFirstTime(11));
  46. System.out.println("获取本季度最后一天:" + tt.getThisSeasonFinallyTime(11));
  47. System.out.println("获取两个日期之间间隔天数2008-12-1~2008-9.29:"
  48. + CalendarUtil.getTwoDay("2008-12-1", "2008-9-29"));
  49. System.out.println("获取当前月的第几周:" + tt.getWeekOfMonth());
  50. System.out.println("获取当前年份:" + tt.getYear());
  51. System.out.println("获取当前月份:" + tt.getMonth());
  52. System.out.println("获取今天在本年的第几天:" + tt.getDayOfYear());
  53. System.out.println("获得今天在本月的第几天(获得当前日):" + tt.getDayOfMonth());
  54. System.out.println("获得今天在本周的第几天:" + tt.getDayOfWeek());
  55. System.out.println("获得半年后的日期:"
  56. + tt.convertDateToString(tt.getTimeYearNext()));
  57. }
  58. /**
  59. * 获得当前年份
  60. *
  61. * @return
  62. */
  63. public static int getYear() {
  64. return Calendar.getInstance().get(Calendar.YEAR);
  65. }
  66. /**
  67. * 获得当前月份
  68. *
  69. * @return
  70. */
  71. public static int getMonth() {
  72. return Calendar.getInstance().get(Calendar.MONTH) + 1;
  73. }
  74. /**
  75. * 获得今天在本年的第几天
  76. *
  77. * @return
  78. */
  79. public static int getDayOfYear() {
  80. return Calendar.getInstance().get(Calendar.DAY_OF_YEAR);
  81. }
  82. /**
  83. * 获得今天在本月的第几天(获得当前日)
  84. *
  85. * @return
  86. */
  87. public static int getDayOfMonth() {
  88. return Calendar.getInstance().get(Calendar.DAY_OF_MONTH);
  89. }
  90. /**
  91. * 获得今天在本周的第几天
  92. *
  93. * @return
  94. */
  95. public static int getDayOfWeek() {
  96. return Calendar.getInstance().get(Calendar.DAY_OF_WEEK);
  97. }
  98. /**
  99. * 获得今天是这个月的第几周
  100. *
  101. * @return
  102. */
  103. public static int getWeekOfMonth() {
  104. return Calendar.getInstance().get(Calendar.DAY_OF_WEEK_IN_MONTH);
  105. }
  106. /**
  107. * 获得半年后的日期
  108. *
  109. * @return
  110. */
  111. public static Date getTimeYearNext() {
  112. Calendar.getInstance().add(Calendar.DAY_OF_YEAR, 183);
  113. return Calendar.getInstance().getTime();
  114. }
  115. /**
  116. * 将日期转换成字符串
  117. *
  118. * @param dateTime
  119. * @return
  120. */
  121. public static String convertDateToString(Date dateTime) {
  122. SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
  123. return df.format(dateTime);
  124. }
  125. /**
  126. * 得到二个日期间的间隔天数
  127. *
  128. * @param sj1
  129. * @param sj2
  130. * @return
  131. */
  132. public static String getTwoDay(String sj1, String sj2) {
  133. SimpleDateFormat myFormatter = new SimpleDateFormat("yyyy-MM-dd");
  134. long day = 0;
  135. try {
  136. java.util.Date date = myFormatter.parse(sj1);
  137. java.util.Date mydate = myFormatter.parse(sj2);
  138. day = (date.getTime() - mydate.getTime()) / (24 * 60 * 60 * 1000);
  139. } catch (Exception e) {
  140. return "";
  141. }
  142. return day + "";
  143. }
  144. /**
  145. * 根据一个日期,返回是星期几的字符串
  146. *
  147. * @param sdate
  148. * @return
  149. */
  150. public static String getWeek(String sdate) {
  151. // 再转换为时间
  152. Date date = CalendarUtil.strToDate(sdate);
  153. Calendar c = Calendar.getInstance();
  154. c.setTime(date);
  155. // int hour=c.get(Calendar.DAY_OF_WEEK);
  156. // hour中存的就是星期几了,其范围 1~7
  157. // 1=星期日 7=星期六,其他类推
  158. return new SimpleDateFormat("EEEE").format(c.getTime());
  159. }
  160. /**
  161. * 将短时间格式字符串转换为时间 yyyy-MM-dd
  162. *
  163. * @param strDate
  164. * @return
  165. */
  166. public static Date strToDate(String strDate) {
  167. SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
  168. ParsePosition pos = new ParsePosition(0);
  169. Date strtodate = formatter.parse(strDate, pos);
  170. return strtodate;
  171. }
  172. /**
  173. * 两个时间之间的天数
  174. *
  175. * @param date1
  176. * @param date2
  177. * @return
  178. */
  179. public static long getDays(String date1, String date2) {
  180. if (date1 == null || date1.equals(""))
  181. return 0;
  182. if (date2 == null || date2.equals(""))
  183. return 0;
  184. // 转换为标准时间
  185. SimpleDateFormat myFormatter = new SimpleDateFormat("yyyy-MM-dd");
  186. java.util.Date date = null;
  187. java.util.Date mydate = null;
  188. try {
  189. date = myFormatter.parse(date1);
  190. mydate = myFormatter.parse(date2);
  191. } catch (Exception e) {
  192. }
  193. long day = (date.getTime() - mydate.getTime()) / (24 * 60 * 60 * 1000);
  194. return day;
  195. }
  196. /**
  197. * 计算当月最后一天,返回字符串
  198. *
  199. * @return
  200. */
  201. public String getDefaultDay() {
  202. String str = "";
  203. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  204. Calendar lastDate = Calendar.getInstance();
  205. lastDate.set(Calendar.DATE, 1);// 设为当前月的1号
  206. lastDate.add(Calendar.MONTH, 1);// 加一个月,变为下月的1号
  207. lastDate.add(Calendar.DATE, -1);// 减去一天,变为当月最后一天
  208. str = sdf.format(lastDate.getTime());
  209. return str;
  210. }
  211. /**
  212. * 上月第一天
  213. *
  214. * @return
  215. */
  216. public String getPreviousMonthFirst() {
  217. String str = "";
  218. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  219. Calendar lastDate = Calendar.getInstance();
  220. lastDate.set(Calendar.DATE, 1);// 设为当前月的1号
  221. lastDate.add(Calendar.MONTH, -1);// 减一个月,变为下月的1号
  222. // lastDate.add(Calendar.DATE,-1);//减去一天,变为当月最后一天
  223. str = sdf.format(lastDate.getTime());
  224. return str;
  225. }
  226. /**
  227. * 获取当月第一天
  228. *
  229. * @return
  230. */
  231. public String getFirstDayOfMonth() {
  232. String str = "";
  233. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  234. Calendar lastDate = Calendar.getInstance();
  235. lastDate.set(Calendar.DATE, 1);// 设为当前月的1号
  236. str = sdf.format(lastDate.getTime());
  237. return str;
  238. }
  239. /**
  240. * 获得本周星期日的日期
  241. *
  242. * @return
  243. */
  244. public String getCurrentWeekday() {
  245. weeks = 0;
  246. int mondayPlus = this.getMondayPlus();
  247. GregorianCalendar currentDate = new GregorianCalendar();
  248. currentDate.add(GregorianCalendar.DATE, mondayPlus + 6);
  249. Date monday = currentDate.getTime();
  250. DateFormat df = DateFormat.getDateInstance();
  251. String preMonday = df.format(monday);
  252. return preMonday;
  253. }
  254. /**
  255. * 获取当天时间
  256. *
  257. * @param dateformat
  258. * @return
  259. */
  260. public String getNowTime(String dateformat) {
  261. Date now = new Date();
  262. SimpleDateFormat dateFormat = new SimpleDateFormat(dateformat);// 可以方便地修改日期格式
  263. String hehe = dateFormat.format(now);
  264. return hehe;
  265. }
  266. /**
  267. * 获得当前日期与本周日相差的天数
  268. *
  269. * @return
  270. */
  271. private int getMondayPlus() {
  272. Calendar cd = Calendar.getInstance();
  273. // 获得今天是一周的第几天,星期日是第一天,星期二是第二天......
  274. int dayOfWeek = cd.get(Calendar.DAY_OF_WEEK) - 1; // 因为按中国礼拜一作为第一天所以这里减1
  275. if (dayOfWeek == 1) {
  276. return 0;
  277. } else {
  278. return 1 - dayOfWeek;
  279. }
  280. }
  281. /**
  282. * 获得本周一的日期
  283. *
  284. * @return
  285. */
  286. public String getMondayOFWeek() {
  287. weeks = 0;
  288. int mondayPlus = this.getMondayPlus();
  289. GregorianCalendar currentDate = new GregorianCalendar();
  290. currentDate.add(GregorianCalendar.DATE, mondayPlus);
  291. Date monday = currentDate.getTime();
  292. DateFormat df = DateFormat.getDateInstance();
  293. String preMonday = df.format(monday);
  294. return preMonday;
  295. }
  296. /**
  297. * 获得相应周的周六的日期
  298. *
  299. * @return
  300. */
  301. public String getSaturday() {
  302. int mondayPlus = this.getMondayPlus();
  303. GregorianCalendar currentDate = new GregorianCalendar();
  304. currentDate.add(GregorianCalendar.DATE, mondayPlus + 7 * weeks + 6);
  305. Date monday = currentDate.getTime();
  306. DateFormat df = DateFormat.getDateInstance();
  307. String preMonday = df.format(monday);
  308. return preMonday;
  309. }
  310. /**
  311. * 获得上周星期日的日期
  312. *
  313. * @return
  314. */
  315. public String getPreviousWeekSunday() {
  316. weeks = 0;
  317. weeks--;
  318. int mondayPlus = this.getMondayPlus();
  319. GregorianCalendar currentDate = new GregorianCalendar();
  320. currentDate.add(GregorianCalendar.DATE, mondayPlus + weeks);
  321. Date monday = currentDate.getTime();
  322. DateFormat df = DateFormat.getDateInstance();
  323. String preMonday = df.format(monday);
  324. return preMonday;
  325. }
  326. /**
  327. * 获得上周星期一的日期
  328. *
  329. * @return
  330. */
  331. public String getPreviousWeekday() {
  332. weeks--;
  333. int mondayPlus = this.getMondayPlus();
  334. GregorianCalendar currentDate = new GregorianCalendar();
  335. currentDate.add(GregorianCalendar.DATE, mondayPlus + 7 * weeks);
  336. Date monday = currentDate.getTime();
  337. DateFormat df = DateFormat.getDateInstance();
  338. String preMonday = df.format(monday);
  339. return preMonday;
  340. }
  341. /**
  342. * 获得下周星期一的日期
  343. */
  344. public String getNextMonday() {
  345. weeks++;
  346. int mondayPlus = this.getMondayPlus();
  347. GregorianCalendar currentDate = new GregorianCalendar();
  348. currentDate.add(GregorianCalendar.DATE, mondayPlus + 7);
  349. Date monday = currentDate.getTime();
  350. DateFormat df = DateFormat.getDateInstance();
  351. String preMonday = df.format(monday);
  352. return preMonday;
  353. }
  354. /**
  355. * 获得下周星期日的日期
  356. */
  357. public String getNextSunday() {
  358. int mondayPlus = this.getMondayPlus();
  359. GregorianCalendar currentDate = new GregorianCalendar();
  360. currentDate.add(GregorianCalendar.DATE, mondayPlus + 7 + 6);
  361. Date monday = currentDate.getTime();
  362. DateFormat df = DateFormat.getDateInstance();
  363. String preMonday = df.format(monday);
  364. return preMonday;
  365. }
  366. private int getMonthPlus() {
  367. Calendar cd = Calendar.getInstance();
  368. int monthOfNumber = cd.get(Calendar.DAY_OF_MONTH);
  369. cd.set(Calendar.DATE, 1);// 把日期设置为当月第一天
  370. cd.roll(Calendar.DATE, -1);// 日期回滚一天,也就是最后一天
  371. MaxDate = cd.get(Calendar.DATE);
  372. if (monthOfNumber == 1) {
  373. return -MaxDate;
  374. } else {
  375. return 1 - monthOfNumber;
  376. }
  377. }
  378. /**
  379. * 获得上月最后一天的日期
  380. *
  381. * @return
  382. */
  383. public String getPreviousMonthEnd() {
  384. String str = "";
  385. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  386. Calendar lastDate = Calendar.getInstance();
  387. lastDate.add(Calendar.MONTH, -1);// 减一个月
  388. lastDate.set(Calendar.DATE, 1);// 把日期设置为当月第一天
  389. lastDate.roll(Calendar.DATE, -1);// 日期回滚一天,也就是本月最后一天
  390. str = sdf.format(lastDate.getTime());
  391. return str;
  392. }
  393. /**
  394. * 获得下个月第一天的日期
  395. *
  396. * @return
  397. */
  398. public String getNextMonthFirst() {
  399. String str = "";
  400. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  401. Calendar lastDate = Calendar.getInstance();
  402. lastDate.add(Calendar.MONTH, 1);// 减一个月
  403. lastDate.set(Calendar.DATE, 1);// 把日期设置为当月第一天
  404. str = sdf.format(lastDate.getTime());
  405. return str;
  406. }
  407. /**
  408. * 获得下个月最后一天的日期
  409. *
  410. * @return
  411. */
  412. public String getNextMonthEnd() {
  413. String str = "";
  414. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  415. Calendar lastDate = Calendar.getInstance();
  416. lastDate.add(Calendar.MONTH, 1);// 加一个月
  417. lastDate.set(Calendar.DATE, 1);// 把日期设置为当月第一天
  418. lastDate.roll(Calendar.DATE, -1);// 日期回滚一天,也就是本月最后一天
  419. str = sdf.format(lastDate.getTime());
  420. return str;
  421. }
  422. /**
  423. * 获得明年最后一天的日期
  424. *
  425. * @return
  426. */
  427. public String getNextYearEnd() {
  428. String str = "";
  429. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  430. Calendar lastDate = Calendar.getInstance();
  431. lastDate.add(Calendar.YEAR, 1);// 加一个年
  432. lastDate.set(Calendar.DAY_OF_YEAR, 1);
  433. lastDate.roll(Calendar.DAY_OF_YEAR, -1);
  434. str = sdf.format(lastDate.getTime());
  435. return str;
  436. }
  437. /**
  438. * 获得明年第一天的日期
  439. *
  440. * @return
  441. */
  442. public String getNextYearFirst() {
  443. String str = "";
  444. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  445. Calendar lastDate = Calendar.getInstance();
  446. lastDate.add(Calendar.YEAR, 1);// 加一个年
  447. lastDate.set(Calendar.DAY_OF_YEAR, 1);
  448. str = sdf.format(lastDate.getTime());
  449. return str;
  450. }
  451. /**
  452. * 获得本年有多少天
  453. *
  454. * @return
  455. */
  456. private int getMaxYear() {
  457. Calendar cd = Calendar.getInstance();
  458. cd.set(Calendar.DAY_OF_YEAR, 1);// 把日期设为当年第一天
  459. cd.roll(Calendar.DAY_OF_YEAR, -1);// 把日期回滚一天。
  460. int MaxYear = cd.get(Calendar.DAY_OF_YEAR);
  461. return MaxYear;
  462. }
  463. private int getYearPlus() {
  464. Calendar cd = Calendar.getInstance();
  465. int yearOfNumber = cd.get(Calendar.DAY_OF_YEAR);// 获得当天是一年中的第几天
  466. cd.set(Calendar.DAY_OF_YEAR, 1);// 把日期设为当年第一天
  467. cd.roll(Calendar.DAY_OF_YEAR, -1);// 把日期回滚一天。
  468. int MaxYear = cd.get(Calendar.DAY_OF_YEAR);
  469. if (yearOfNumber == 1) {
  470. return -MaxYear;
  471. } else {
  472. return 1 - yearOfNumber;
  473. }
  474. }
  475. /**
  476. * 获得本年第一天的日期
  477. *
  478. * @return
  479. */
  480. public String getCurrentYearFirst() {
  481. int yearPlus = this.getYearPlus();
  482. GregorianCalendar currentDate = new GregorianCalendar();
  483. currentDate.add(GregorianCalendar.DATE, yearPlus);
  484. Date yearDay = currentDate.getTime();
  485. DateFormat df = DateFormat.getDateInstance();
  486. String preYearDay = df.format(yearDay);
  487. return preYearDay;
  488. }
  489. // 获得本年最后一天的日期 *
  490. public String getCurrentYearEnd() {
  491. Date date = new Date();
  492. SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy");// 可以方便地修改日期格式
  493. String years = dateFormat.format(date);
  494. return years + "-12-31";
  495. }
  496. // 获得上年第一天的日期 *
  497. public String getPreviousYearFirst() {
  498. Date date = new Date();
  499. SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy");// 可以方便地修改日期格式
  500. String years = dateFormat.format(date);
  501. int years_value = Integer.parseInt(years);
  502. years_value--;
  503. return years_value + "-1-1";
  504. }
  505. // 获得上年最后一天的日期
  506. public String getPreviousYearEnd() {
  507. weeks--;
  508. int yearPlus = this.getYearPlus();
  509. GregorianCalendar currentDate = new GregorianCalendar();
  510. currentDate.add(GregorianCalendar.DATE, yearPlus + MaxYear * weeks
  511. + (MaxYear - 1));
  512. Date yearDay = currentDate.getTime();
  513. DateFormat df = DateFormat.getDateInstance();
  514. String preYearDay = df.format(yearDay);
  515. return preYearDay;
  516. }
  517. /**
  518. * 获得本季度第一天
  519. *
  520. * @param month
  521. * @return
  522. */
  523. public String getThisSeasonFirstTime(int month) {
  524. int array[][] = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 }, { 10, 11, 12 } };
  525. int season = 1;
  526. if (month >= 1 && month <= 3) {
  527. season = 1;
  528. }
  529. if (month >= 4 && month <= 6) {
  530. season = 2;
  531. }
  532. if (month >= 7 && month <= 9) {
  533. season = 3;
  534. }
  535. if (month >= 10 && month <= 12) {
  536. season = 4;
  537. }
  538. int start_month = array[season - 1][0];
  539. int end_month = array[season - 1][2];
  540. Date date = new Date();
  541. SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy");// 可以方便地修改日期格式
  542. String years = dateFormat.format(date);
  543. int years_value = Integer.parseInt(years);
  544. int start_days = 1;// years+"-"+String.valueOf(start_month)+"-1";//getLastDayOfMonth(years_value,start_month);
  545. int end_days = getLastDayOfMonth(years_value, end_month);
  546. String seasonDate = years_value + "-" + start_month + "-" + start_days;
  547. return seasonDate;
  548. }
  549. /**
  550. * 获得本季度最后一天
  551. *
  552. * @param month
  553. * @return
  554. */
  555. public String getThisSeasonFinallyTime(int month) {
  556. int array[][] = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 }, { 10, 11, 12 } };
  557. int season = 1;
  558. if (month >= 1 && month <= 3) {
  559. season = 1;
  560. }
  561. if (month >= 4 && month <= 6) {
  562. season = 2;
  563. }
  564. if (month >= 7 && month <= 9) {
  565. season = 3;
  566. }
  567. if (month >= 10 && month <= 12) {
  568. season = 4;
  569. }
  570. int start_month = array[season - 1][0];
  571. int end_month = array[season - 1][2];
  572. Date date = new Date();
  573. SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy");// 可以方便地修改日期格式
  574. String years = dateFormat.format(date);
  575. int years_value = Integer.parseInt(years);
  576. int start_days = 1;// years+"-"+String.valueOf(start_month)+"-1";//getLastDayOfMonth(years_value,start_month);
  577. int end_days = getLastDayOfMonth(years_value, end_month);
  578. String seasonDate = years_value + "-" + end_month + "-" + end_days;
  579. return seasonDate;
  580. }
  581. /**
  582. * 获取某年某月的最后一天
  583. *
  584. * @param year
  585. * 年
  586. * @param month
  587. * 月
  588. * @return 最后一天
  589. */
  590. private int getLastDayOfMonth(int year, int month) {
  591. if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8
  592. || month == 10 || month == 12) {
  593. return 31;
  594. }
  595. if (month == 4 || month == 6 || month == 9 || month == 11) {
  596. return 30;
  597. }
  598. if (month == 2) {
  599. if (isLeapYear(year)) {
  600. return 29;
  601. } else {
  602. return 28;
  603. }
  604. }
  605. return 0;
  606. }
  607. /**
  608. * 是否闰年
  609. *
  610. * @param year
  611. * 年
  612. * @return
  613. */
  614. public boolean isLeapYear(int year) {
  615. return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
  616. }
  617. /**
  618. * 是否闰年
  619. *
  620. * @param year
  621. * @return
  622. */
  623. public boolean isLeapYear2(int year) {
  624. return new GregorianCalendar().isLeapYear(year);
  625. }
  626. }
  627. </PRE>
分享到:
评论

相关推荐

    iTsai-Webtools.zip

    * 1).iTsai.ajax: 异步数据请求封装; * 2).iTsai.array: 数组的基本操作; * 3).iTsai.calendar: 日期时间操作; * 4).iTsai.form: 表单操作; * 5).iTsai.layer: 页面遮罩层; * 6).iTsai.msg: 提示信息; * 7...

    Java语音学习,基础教程

    熟悉常用API:包括Date、DateFormat、Calendar、System和StringBuilde等,这些是在Java编程中经常用到的类和方法。 学习集合:理解Java中的Collection、泛型、List、Set、Collections、Map和HashMap等概念和用法。 ...

    基础(二)

    常用方法1.1.2.字符串比较1.1.3. StringBuffer与 StringBuilder1.1.4. String、StringBuffer、StringBuilder的区别1.1.5.封装类比较1.2. Math类1.3. Arrays 类1.4. System 类1.5. Object 类1.6. Date 类1.6.1.日期...

    JAVA基础课程讲义

    String类的常用方法(已讲过,不再讲!) 120 StringBuffer和StringBuilder 121 String和StringBuffer和StringBuilder使用要点 123 时间处理相关类 124 Date时间类(java.util.Date) 124 DateFormat类和...

    我的js(日历,表单操作,js验证)

    包括常用JS操作(复选框、单选框、下拉框) 日历控件,支持换肤等 封装的js表单验证 demo目录里有js库(jskey_core)中提供的部分功能例子 其中themes目录里jskey_core中用到的样式,与js文件同级存放。 如果想不想...

    smart GWT 3.1

    比如可 编辑的树形表格、查询常用的过滤器创建器和类似 Google Calendar 的日历等 等。 内置的数据整合功能。利用 SmartClient 的 MVC 模式,用户可以通过定义 数据源(Data Source),很容易地开发出能对服务器端...

    AIC的Java课程1-6章

    第3版 机械工业出版社  教学内容和要求 知识点 重要程度 使用频度 难度 Java 入门 高 中 易 变量和运算符 高 高 中 控制结构 高 高 易 数组 高 高 中 方法 很高 高 中 封装 很高 很高 难...

    Java开发详解.zip

    031105_【第11章:Java常用类库】_日期操作类(Date、Calendar)笔记.pdf 031106_【第11章:Java常用类库】_日期操作类(DateFormat、SimpleDateFormat)笔记.pdf 031107_〖第11章:Java常用类库〗_实例操作:取得...

    Java 2实用教程(第三版)实验指导与习题解答

    实验1 String类的常用方法 19 实验2 比较日期的大小 21 实验3 处理大整数 22 上机实践6 组件及事件处理 23 实验1 算术测试 23 实验2 信号灯 25 实验3 布局与日历 28 上机实践7 组件及事件处理2 31 实验1 方程求根 31...

    一个简单的开源Android工具类库

    CalendarUtils Calendar Unility Class ClipboardUtils Clipboard Unility Class CollectionUtils Collection Unility Class CommonUtils Common Unility Class CpuUtils Cpu Unility Class DeviceUtils ...

    Java基础知识点总结.docx

    五、 封装(面向对象特征之一)★★★★ 23 六、 继承(面向对象特征之一)★★★★ 25 七、 接口(面向对象特征之一)★★★★ 28 八、 多态(面向对象特征之一)★★★★ 30 九、 java.lang.Object 31 十、 异常★...

    Java JDK 7学习笔记(国内第一本Java 7,前期版本累计销量5万册)

    12.2.3 使用calendar 393 12.3 规则表示式 395 12.3.1 定义规则表示式 396 12.3.2 pattern与matcher 403 12.4 nio2文件系统 405 12.4.1 api架构概述 405 12.4.2 操作路径 406 12.4.3 属性读取与设定 ...

    疯狂JAVA讲义

    9.4.2 Calendar类 334 9.4.3 TimeZone类 337 9.5 正则表达式 338 9.5.1 创建正则表达式 338 9.5.2 使用正则表达式 341 9.6 程序国际化 345 9.6.1 Java国际化的思路 346 9.6.2 Java支持的语言和国家 346 ...

    ASP.NET 2.0+SQL Server 2005全程指南-源代码

    3.3.1 Calendar控件的应用 3.3.2 AdRotator控件的应用 3.3.3 Xml控件的应用  3.4 本章小结 第4章 验证控件 4.1 非空验证 4.2 范围验证 4.3 比较验证 4.4 使用正则表达式验证 4.5 自定义验证 4.6 本章小...

    Java开发技术大全(500个源代码).

    differ.java 测试静态方法与实例方法之间的区别 forefather.java 一个简单的基类 grandson.java 上面这个类的子类 hasConstructor.java 拥有构造器的类 hasFinalFun.java 拥有最终方法的类 hasRecall.java ...

    ASP.NET3.5从入门到精通

    5.10 日历控件(Calendar) 5.10.1 日历控件的样式 5.10.2 日历控件的事件 5.11 广告控件(AdRotator) 5.12 文件上传控件(FileUpload) 5.13 视图控件(MultiView 和View) 5.14 表控件(Table) 5.15 向导控件...

    Java范例开发大全 (源程序)

     11.3 Date类和Calendar类 324  实例191 使用Date类获取系统的当前时间 324  实例192 使用DateFormat类获取系统的当前时间 325  实例193 使用GregorianCalendar类获取系统的当前时间 326  实例194 使用...

    java范例开发大全(pdf&源码)

    11.3 Date类和Calendar类 324 实例191 使用Date类获取系统的当前时间 324 实例192 使用DateFormat类获取系统的当前时间 325 实例193 使用GregorianCalendar类获取系统的当前时间 326 实例194 使用SimpleDateFormat类...

    java范例开发大全源代码

     11.3 Date类和Calendar类 324  实例191 使用Date类获取系统的当前时间 324  实例192 使用DateFormat类获取系统的当前时间 325  实例193 使用GregorianCalendar类获取系统的当前时间 326  实例194 使用...

Global site tag (gtag.js) - Google Analytics