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

jAvA 年份加减

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

给你一个参考如下: 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...

@Test public void testTime() throws ParseException { String time1 = "2015-5-4 12:15:17"; String time2 = "2015-5-4 12:13:11"; SimpleDateFormat sdf = new SimpleDateFormat("YYYY-MM-DD HH:mm:ss"); Date date1 = sdf.parse(time1); Dat...

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

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

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

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

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

用Date类的compareTo方法,返回一个int型的数这个就是你要的结果 学习一下怎么查帮助文档吧,比较有用

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