nynw.net
当前位置:首页 >> jAvA获取当前时间的前一天 >>

jAvA获取当前时间的前一天

public static void main(String[] args){ Date dNow = new Date(); //当前时间 Date dBefore = new Date(); Calendar calendar = Calendar.getInstance(); //得到日历 calendar.setTime(dNow);//把当前时间赋给日历 calendar.add(Calendar.DAY_...

代码如下: String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; Date dNow = new Date(); //当前时间Date dBefore = new Date(); Calendar calendar = Calendar.getInstance(); //得...

我想到最简单的: System.out.println(new Date()); System.out.println(new Date(System.currentTimeMillis() - 24*60*60)); 当然,也可用Calendar类,如: http://blog.csdn.net/zerogotosum/article/details/1671314

我想到最简单的: System.out.println(new Date()); System.out.println(new Date(System.currentTimeMillis() - 24*60*60)); 当然,也可用Calendar类,如: http://blog.csdn.net/zerogotosum/article/details/1671314

当前时间 Date(System.currentTimeMillis()) 前一天:Calendar cd = Calendar.getInstance(); cd.setTime(Date(System.currentTimeMillis())); cd.add(Calendar.DATE, -1);// 减少一天 return cd.getTime();

SimpleDateFormat dft = new SimpleDateFormat("yyyy-MM-dd"); Date beginDate = new Date(); Calendar date = Calendar.getInstance(); date.setTime(beginDate); date.set(Calendar.DATE, date.get(Calendar.DATE) - 1); Date endDate = dft.p...

Calendar now = Calendar.getInstance(); // 现在的时间 now.roll(Calendar.DAY_OF_YEAR, -1); //昨天如果要获得的是Date对象,则now.getTime()返回的就是Date对象了

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");//昨天Calendar calendar = Calendar.getInstance();calendar.add(Calendar.DATE, -1);System.out.println(dateFormat.format(calendar.getTime()));//本月第一天calendar.cl...

Calendar类的add方法,第二个引数用负数就行,。

网站首页 | 网站地图
All rights reserved Powered by www.nynw.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com