A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© qihuan 中级黑马   /  2015-7-13 08:22  /  349 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

  1. package practice;

  2. import java.util.Calendar;

  3. /**
  4. * 练习:
  5. * 1.获取任意年的的二月有多少天
  6. * 2.获取昨天的这个时刻
  7. * @author Qihuan
  8. *
  9. */
  10. public class CalendarTest {
  11.         public static void main(String[] args) {
  12.                 Calendar c = Calendar.getInstance();
  13.                
  14.                 //2.获取昨天的这个时刻
  15.                 printTimeYesterday(c);
  16.                
  17.                 //1.获取任意年的二月有多少天
  18.                 printFebruary(c,2015);
  19.         }

  20.        

  21.         private static void printFebruary(Calendar c, int year) {
  22.                 // TODO Auto-generated method stub
  23.                 c.set(year, 2, 1);
  24.                 c.add(Calendar.DAY_OF_MONTH, -1);
  25.                 System.out.print(year+"年的二月有:");
  26.                 System.out.println(c.get(Calendar.DAY_OF_MONTH)+"天");
  27.         }
  28.        
  29.         private static void printTimeYesterday(Calendar c) {
  30.                 // TODO Auto-generated method stub
  31.                 c.add(Calendar.DAY_OF_MONTH, -1);
  32.                 System.out.print(c.get(Calendar.DAY_OF_MONTH)+"日");
  33.                 System.out.println(c.get(Calendar.HOUR)+"时");
  34.         }
  35. }
复制代码


0 个回复

您需要登录后才可以回帖 登录 | 加入黑马