tnfh.net
当前位置:首页 >> jAvA当前时间加一小时 >>

jAvA当前时间加一小时

Date date = new Date(); System.out.println("data1 = "+date.toLocaleString()); date.setHours(new Date().getHours()+3); System.out.println("date2 = "+date.toLocaleString()); 运行结果: data1 = 2012-7-25 10:58:35 date2 = 2012-7-25...

一、步骤如下: long currentTime = System.currentTimeMillis() + 30 * 60 * 1000; Date date = new Date(currentTime); DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");String nowTime="";nowTime= df.format(date);System.out...

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

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

推迟一周示例:Calendar curr = Calendar.getInstance();curr.set(Calendar.DAY_OF_MONTH,curr.get(Calendar.DAY_OF_MONTH)+7);Date date=curr.getTime(); 推迟一年示例:Calendar curr = Calendar.getInstance();curr.set(Calendar.YEAR,curr.g...

public static void main(String[] args) { SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Calendar c=Calendar.getInstance(); System.out.println(sdf.format(c.getTime())); c.add(Calendar.HOUR_OF_DAY, -1);//1小时...

给时间加个格式: Date date =new Date(System.currentTimeMillis()); SimpleDateFormat formatter = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss "); String time = formatter.format(date); System.out.println(time); 这样你要取整的话 , ...

所有在date上的日期操作都需要通过添加毫秒到date才能完成。例如,如果我们想增加6个小时,那么我们需要将6小时换算成毫秒。6小时= 6 * 60 * 60 * 1000毫秒。请看以下的例子。 Date date = new Date(); //Increase time by 6 hrs date.setTime(d...

Calendar begin=Calendar.getInstance(); begin.setTime(....);//给定起始时间 //比如100小时 for(int i=0;i

cal.add(Calendar.MINUTE,4.5*60);

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