nynw.net
当前位置:首页 >> jAvA中时间的加减法怎么做? >>

jAvA中时间的加减法怎么做?

最简单的方法应该是,换成毫秒,直接加减之后再换回24进制时

1.用java.util.Calender来实现 Calendar calendar=Calendar.getInstance();calendar.setTime(new Date());System.out.println(calendar.get(Calendar.DAY_OF_MONTH));//今天的日期calendar.set(Calendar.DAY_OF_MONTH,calendar.get(Calendar.DAY...

附上代码: Date date = new Date("2014/1/10 18:20"); Date date2 = new Date("2014/1/11 3:5"); long temp = date2.getTime() - date.getTime(); //相差毫秒数 long hours = temp / 1000 / 3600; //相差小时数 long temp2 = temp % (1000 * 3...

df.format(new Date(d.getTime() - 30 * 24 * 60 * 60 * 1000L)) 最后加个L,这个计算超过了Integer最大值,变成负数了,转换为Long就好了

String str = "2013-07-18";SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");try {Date myDate = formatter.parse(str);Calendar c = Calendar.getInstance();c.setTime(myDate);c.add(Calendar.MONTH, 8);myDate = c.getTime...

Java代码 public class test1 { public static void main(String[] args) { Calendar c = Calendar.getInstance(); int year=c.get(Calendar.YEAR); int month=c.get(Calendar.MONTH)+1; int date=c.get(Calendar.DATE); System.out.println("今...

给你一个参考如下: import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class DateTestUtil { public static void main(String[] args) throws Exception { SimpleDateFormat sdf=new SimpleDateFo...

Calendar currentDate = new GregorianCalendar(); currentDate.setFirstDayOfWeek(Calendar.MONDAY); currentDate.set(Calendar.HOUR_OF_DAY, 0); //小时加减 正数是加,负数是减 currentDate.set(Calendar.MINUTE, 0); //分钟加减 currentDate...

应该转成long型的 long tvodTime = Long.valueOf(time);

将字符串转换成数字: 有两种方法: 第一种: 比如说;a="123",b=2,那么int num = Integer.parseInt(a); 然后与另外数字加减; 第二种: 运用BigDecimal num = new BigDecimal(a); BigDecimal num2 = new BigDecimal(b); BigDecimal result = nu...

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