你好,游客 登录 注册 搜索
背景:
阅读新闻

Android使用GridView实现日历功能(详细代码)

[日期:2013-01-25] 来源:Linux社区  作者:onlyonecoder [字体:大 中 小]

计算类

import java.util.Calendar;

public class SpecialCalendar {

 private int daysOfMonth = 0;      //某月的天数
 private int dayOfWeek = 0;        //具体某一天是星期几

 
 
 
 // 判断是否为闰年
 public boolean isLeapYear(int year) {
  if (year % 100 == 0 && year % 400 == 0) {
   return true;
  } else if (year % 100 != 0 && year % 4 == 0) {
   return true;
  }
  return false;
 }

 //得到某月有多少天数
 public int getDaysOfMonth(boolean isLeapyear, int month) {
  switch (month) {
  case 1:
  case 3:
  case 5:
  case 7:
  case 8:
  case 10:
  case 12:
   daysOfMonth = 31;
   break;
  case 4:
  case 6:
  case 9:
  case 11:
   daysOfMonth = 30;
   break;
  case 2:
   if (isLeapyear) {
    daysOfMonth = 29;
   } else {
    daysOfMonth = 28;
   }

  }
  return daysOfMonth;
 }
 
 //指定某年中的某月的第一天是星期几
 public int getWeekdayOfMonth(int year, int month){
  Calendar cal = Calendar.getInstance();
  cal.set(year, month-1, 1);
  dayOfWeek = cal.get(Calendar.DAY_OF_WEEK)-1;
  return dayOfWeek;
 }
 
 
}

linux
本文评论   查看全部评论 (1)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款
第 1 楼
* 匿名 发表于 2013/3/12 10:25:15
能不能发日历的源码到我的邮箱 谢谢 458590041@qq.com