最近在做一个人资项目,需要结算当前时间的上个月工资。起初想的是用
Date now = new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"),获得当前时间再转换成数字再计算,但感觉不精确,转换也比较麻烦,求教高手有没有简单的方法
Date now = new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"),获得当前时间再转换成数字再计算,但感觉不精确,转换也比较麻烦,求教高手有没有简单的方法
解决方案 »
- java错误请教
- 【如何使用Struts1实现批量更新?】
- 求PD生成hibernate的模版配置文件
- Cannot instantiate class: org.jnp.interfaces.NamingContextFactory [Root excepti
- AJAX的轮询方式指的是什么?
- struts标签是否可以作这样的循环控制
- spring配置文件的热部署!请高手回答!。
- 求代码:离开页面提示加入收藏夹,如果已经加入,则不要提示。
- 求助:学习hibernate+mysql,Query时出错.check the manual that corresponds to your MySQL server version
- 关于实体BEAN的一些问题
- pdfbox写pdf时,已经读入中日文的字库,但写进去后还是乱码
- 连接数据库时,驱动放置的小问题
c.add(Calendar.MONTH, -1);
return c.getTime();
Calendar c = Calendar.getInstance();
c.add(Calendar.MONTH, -1);
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd")
String preMonth = dateFormat.format(c.getTime());然后扔到你的sql语句去吧
* 取参数月的前一个月
* month: yyyy-MM或yyyyMM
*/
public static String getPreMonth(String _month) {
String preMonth = "";
if (_month.length() == 6) {
_month = _month.substring(0, 4) + "-" + _month.substring(4);
}
if (_month.length() >= 7) {
if (_month.substring(5, 7).equals("01")) { //1月
preMonth = (Integer.parseInt(_month.substring(0, 4))-1) + "-12";
} else {
int im = Integer.parseInt(_month.substring(5, 7))-1;
if (im < 10) {
preMonth = _month.substring(0, 4) + "-0" + im;
} else {
preMonth = _month.substring(0, 4) + "-" + im;
}
}
}
return preMonth;
}
有点啰嗦,就这意思。
c.add(Calendar.MONTH, -1);
return c.getTime();
c.add(Calendar.MONTH, -1);
return c.getTime();
c.add(Calendar.MONTH, -1);
return c.getTime();
*
* 方法描述:取得当前日期的上月或下月日期 ,amount=-1为上月日期,amount=1为下月日期;创建人:jya
* @param s_DateStr
* @param s_FormatStr
* @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 "";
}