Commit d256804af0c2fc82d27aef7a251bd943c635ac65

Authored by zlz
1 parent 3fa2c642

添加方法:计算某天是这一年的第几天

src/main/java/com/bsth/util/DateUtils.java
... ... @@ -133,4 +133,23 @@ public class DateUtils {
133 133 public static int calcHHmmDiff(String fcsj, String zdsj) throws ParseException {
134 134 return (int) (sdfHHmm.parse(zdsj).getTime() - sdfHHmm.parse(fcsj).getTime());
135 135 }
  136 +
  137 + /**
  138 + * 计算某天是这一年的第几天
  139 + * @param str
  140 + * @return
  141 + */
  142 + public static int calcDaynumberInYear(String str){
  143 + int num = 0;
  144 + SimpleDateFormat sdf= new SimpleDateFormat("yyyyMMdd");
  145 + try {
  146 + Date date =sdf.parse(str);
  147 + Calendar calendar = Calendar.getInstance();
  148 + calendar.setTime(date);
  149 + num = calendar.get(Calendar.DAY_OF_YEAR);
  150 + } catch (Exception e) {
  151 + e.printStackTrace();
  152 + }
  153 + return num;
  154 + }
136 155 }
... ...