zoukankan      html  css  js  c++  java
  • 日期工具方法

         项目中经常需要处理日期,下面就常用日期处理方法进行总结统计:

    1、判断是否是闰年

    1  public boolean isLeapYear(int year) {
    2         return ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0));
    3     }
    View Code

    2、根据年和月份计算这个月的最后一天

     1 protected int getLastDayOfMonth(int monthNum, int year) {
     2 
     3         switch (monthNum) {
     4             case 1:
     5                 return 31;
     6             case 2:
     7                 return (isLeapYear(year)) ? 29 : 28;
     8             case 3:
     9                 return 31;
    10             case 4:
    11                 return 30;
    12             case 5:
    13                 return 31;
    14             case 6:
    15                 return 30;
    16             case 7:
    17                 return 31;
    18             case 8:
    19                 return 31;
    20             case 9:
    21                 return 30;
    22             case 10:
    23                 return 31;
    24             case 11:
    25                 return 30;
    26             case 12:
    27                 return 31;
    28             default:
    29                 throw new IllegalArgumentException("Illegal month number: "
    30                         + monthNum);
    31         }
    32     }
    View Code
  • 相关阅读:
    Python--列表、元组
    python之helloworld
    JMeter添加压力机、下载文件
    JMeter接口测试
    Postman接口测试
    浅谈接口测试
    poj3974 最长回文串 exkmp
    GDOI2014 beyond(D2T3) exkmp
    hdu4333 扩展KMP
    poj 3080 KMP
  • 原文地址:https://www.cnblogs.com/jedjia/p/date.html
Copyright © 2011-2022 走看看