www.3112.net > jAvA获取当前时间的前一天

jAvA获取当前时间的前一天

Calendar calendar = Calendar.getInstance(); /* HOUR_OF_DAY 指示一天中的小时 */ calendar.set(Calendar.HOUR_OF_DAY, calendar.get(Calendar.HOUR_OF_DAY) - 1); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Syste...

我想到最简单的: 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();

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

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

public static Date getNextDay(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); calendar.add(Calendar.DAY_OF_MONTH, -1); date = calendar.getTime(); return date; } 自己思考,不做细节解释

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...

方法一: Date date=new Date(); String ss= ""+date.getTime(); Calendar c = Calendar.getInstance(); long l = c.getTimeInMillis(); 方法二: Date dt= new Date(); Long time= dt.getTime(); Long time2=System.currentTimeMillis(); 这里...

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

网站地图

All rights reserved Powered by www.3112.net

copyright ©right 2010-2021。
www.3112.net内容来自网络,如有侵犯请联系客服。zhit325@qq.com