日期工具

来源:互联网 发布:程序员软件 编辑:程序博客网 时间:2024/05/16 19:02
/**
     * 
     * 方法描述:取得当前日期的上月或下月日期 ,amount=-1为上月日期,amount=1为下月日期;
     * @param strDate
     * @param format 日期格式  如 yyyy-MM-dd
     * @param amount 月份增减参数
     * @return
     * @throws Exception
     */
    public static String getFrontBackStrDate(String strDate, String format, int amount) throws Exception {
        if (null == strDate) {
            return null;
        }
        try {
            DateFormat fmt = new SimpleDateFormat(format);
            Calendar c = Calendar.getInstance();
            c.setTime(fmt.parse(strDate));
            c.add(Calendar.MONTH, amount);
            return fmt.format(c.getTime());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }
1 0