js和java得到当前日期和三十天以前日期

来源:互联网 发布:程序员思维 编辑:程序博客网 时间:2024/05/22 05:00

js:

//获取当前日期var myDate = new Date();var nowY = myDate.getFullYear();var nowM = myDate.getMonth()+1;var nowD = myDate.getDate();var enddate = nowY+"-"+(nowM<10 ? "0" + nowM : nowM)+"-"+(nowD<10 ? "0"+ nowD : nowD);//当前日期//获取三十天前日期var lw = new Date(myDate - 1000 * 60 * 60 * 24 * 30);//最后一个数字30可改,30天的意思var lastY = lw.getFullYear();var lastM = lw.getMonth()+1;var lastD = lw.getDate();var startdate=lastY+"-"+(lastM<10 ? "0" + lastM : lastM)+"-"+(lastD<10 ? "0"+ lastD : lastD);//三十天之前日期

===========================================================================================================

java:

//获取当前日期SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");Date today = new Date();String endDate = sdf.format(today);//当前日期//获取三十天前日期Calendar theCa = Calendar.getInstance();theCa.setTime(today);theCa.add(theCa.DATE, -30);//最后一个数字30可改,30天的意思Date start = theCa.getTime();String startDate = sdf.format(start);//三十天之前日期
0 0