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

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

java在当前系统时间加一天主要是使用calendar类的add方法,如下代码: import java.util.Calendar;import java.util.Date;public class ceshi {public static void main(String[] args) {Date date = new Date();// 新建此时的的系统时间System....

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

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

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

Calendar c = Calendar.getInstance();//可以对每个时间域单独修改 int year = c.get(Calendar.YEAR); int month = c.get(Calendar.MONTH); int date = c.get(Calendar.DATE); int hour = c.get(Calendar.HOUR_OF_DAY); int minute = c.get(Cale...

试试, Format f = new SimpleDateFormat("yyyy-MM"); Calendar c = Calendar.getInstance(); System.out.println("之前:" + f.format(c.getTime())); c.add(Calendar.YEAR, -4); System.out.println("之后:" + f.format(c.getTime())); 结果: 之...

JAVA取得昨天的当前时间的方法: 1、定义时间格式 private static final String CURRENT_DATE_FORMAT = "yyyy-MM-dd hh24:mm:ss"; 2、定义format方法内容 public final static String format(Date date) { DateFormat dateFormat = new SimpleDa...

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