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

jAvA获取当前时间的前一天

代码如下: 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

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

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

我想到最简单的: 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类的add方法,第二个引数用负数就行,。

方法一: 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...

public class Test {public static void main(String[] args) {java.util.Calendar rightNow = java.util.Calendar.getInstance();java.text.SimpleDateFormat sim = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//得到当前时间,+3...

网站地图

All rights reserved Powered by www.3112.net

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