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

jAvA获取当前时间的前一天

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

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

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(); 这里...

自己动手帮你写了一个,楼上的写得不够好,原因是,没有充分考虑时间间隔,还有写法不专业 package com.last; import java.io.File; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; import java.u...

Date date=new Date();//取时间 date.clearTime() Calendar calendar = new GregorianCalendar(); calendar.setTime(date); calendar.set(Calendar.HOUR,0) calendar.set(Calendar.MINUTE,0) calendar.set(Calendar.SECOND,0) calendar.set(Cal...

网站地图

All rights reserved Powered by www.3112.net

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