java获取当前时间和前一天日期(实现代码)
废话不多说,上代码
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
Date dNow = new Date(); //当前时间
Date dBefore = new Date();
Calendar calendar = Calendar.getInstance(); //得到日历
calendar.setTime(dNow);//把当前时间赋给日历
calendar.add(Calendar.DAY_OF_MONTH, -1); //设置为前一天
dBefore = calendar.getTime(); //得到前一天的时间
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //设置时间格式
String defaultStartDate = sdf.format(dBefore); //格式化前一天
String defaultEndDate = sdf.format(dNow); //格式化当前时间
System.out.println("前一天的时间是:" + defaultStartDate);
System.out.println("生成的时间是:" + defaultEndDate);
相关文章
Java使用get请求接收List集合数据(json)并导出报表问题
这篇文章主要介绍了Java使用get请求接收List集合数据(json)并导出报表问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教2023-11-11解决mybatis-plus3.4.1分页插件PaginationInterceptor和防止全表更新与删除插件SqlE
这篇文章给大家介绍了在Spring.xml文件中配置mybatis-plus3.4.1分页插件PaginationInterceptor和防止全表更新与删除插件SqlExplainInterceptor过时失效问题解决方案,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧2020-12-12
最新评论