lzth.net
当前位置:首页 >> jAvA 年份加减 >>

jAvA 年份加减

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

附上代码: 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...

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

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("今...

对已日期相减,最高效的做法就是将二者都转换成毫秒,相减之后再根据你的需求进行单位转换,比如你想显示相差的秒数,就除以1000,以此类推,翠花,上代码: /* 随便选两个时间 */ String d1 = "2015-04-17"; String d2 = "2015-06-17"; /* 先转...

import java.util.Date; import org.apache.commons.lang3.time.DateUtils; public class Test { public static void main(String[] args) { Date now = new Date(); // 减一小时 Date add = DateUtils.addHours(now, -1); // 加一小时 Date sub...

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

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

使用calendar类,有add方法,里面可以增加或者减少日期的,输出来就可以额。

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