动态获取上月 年月字段(yyyyMM)

 1 package com.wages.salary.service.common;
 2 
 3 import java.text.SimpleDateFormat;
 4 import java.util.Date;
 5 
 6 public class DateUtil {
 7     public static String  getDate() {
 8         Date date = new Date();
 9         SimpleDateFormat sf = new SimpleDateFormat("yyyyMM");
10         String s = sf.format(date);
11         //String s="201401";
12         String year=s.substring(0,4);
13         String month =s.substring(4,6);
14         int result=0;
15         if(month.equals("01")){
16             int yearInt=Integer.parseInt(year)-1;
17             int monthInt=12;
18              result=yearInt*100+monthInt;
19         }else{
20              result=Integer.parseInt(year+month)-1;
21         }
22           return String.valueOf(result);
23         //System.out.println(result);    
24     }
25 }

 

 

201410------>201409

201401------>201312

posted on 2014-10-21 13:44  @冰糖  阅读(450)  评论(0编辑  收藏  举报

导航