很菜的问题 关于时间问题 1.如何获取当前的系统时间,又如何各种精度很高的日期格式?2.如何判断二个时间参数之间的日期前后?并说明精确的前后差距(如相差5天又一小时23分XX秒XXXms,或刚好相关五天整之类)3.多个时间参数之间,如何求得其平均值? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 查 java api doc 咯.. 1.Date d=new Date();SimpleDateFormat form=new SimpleDateFormat("yyyy:MM:dd ' ' HH:mm:ss ' ' SSS");System.out.println(form.format(d));输出格式:年:月:日 小时:分钟:秒 毫秒2.long one =date1.getTime();//自1970.1.1 00:00:00起的毫秒数lone two = date2.getTime();long time=two-one;然后自己算,注意这里的都是毫秒值;3.long average= (date1.getTime()+date2.getTime()+...+dateN.getTime())/N; Date averDate=new Date(average); System.out.println(form.format(averDate)); 最好用Calendar ,Date的大多数方法已经被Deprecated1. Calendar now = Calendar.getInstance();//精确到毫秒SSSSimpleDateFormat yearAndMonth = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss SSS");String strCurrTime = yearAndMonth.format(now.getTime());now = null;2.计算差值Calendar xmas = new GregorianCalendar(2004, Calendar.DECEMBER, 25);Calendar newyears = new GregorianCalendar(2005, Calendar.JANUARY, 1);// 相差毫秒数long diffMillis = newyears.getTimeInMillis()-xmas.getTimeInMillis();// 相差秒数long diffSecs = diffMillis/(1000); // 相差分数long diffMins = diffMillis/(60*1000); // 相差小时数long diffHours = diffMillis/(60*60*1000); // 相差天数long diffDays = diffMillis/(24*60*60*1000); 3.Calendar xmas = new GregorianCalendar(2004, Calendar.DECEMBER, 25);Calendar newyears = new GregorianCalendar(2005, Calendar.JANUARY, 1);long average= (xmas.getTimeInMillis()+newyears.getTimeInMillis)/2; 报错! 如何相互转换 一个问题 有关jsp页面中out语句与FileReader的问题 用jdom将一个bmp图片编辑到了xml中,请问怎么将bmp图片再还原回来? 有谁用过Torque 多了一条三角裤,散50分先! 空指针问题 在jb6下面编辑class文件以后,在另外的地方调用的问题? ★jbuilder和weblogic配置问题 (下载)MyEclipse下开发Struts和Hibernate的录像。。 !!!!!!ms sql怎么写取出一些连续的记录?参与有分!!!!!!!!!!!!!!!!!!
Date d=new Date();
SimpleDateFormat form=new SimpleDateFormat("yyyy:MM:dd ' ' HH:mm:ss ' ' SSS");
System.out.println(form.format(d));
输出格式:年:月:日 小时:分钟:秒 毫秒2.long one =date1.getTime();//自1970.1.1 00:00:00起的毫秒数
lone two = date2.getTime();
long time=two-one;
然后自己算,注意这里的都是毫秒值;3.long average= (date1.getTime()+date2.getTime()+...+dateN.getTime())/N;
Date averDate=new Date(average);
System.out.println(form.format(averDate));
1. Calendar now = Calendar.getInstance();
//精确到毫秒SSS
SimpleDateFormat yearAndMonth = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss SSS");
String strCurrTime = yearAndMonth.format(now.getTime());
now = null;
2.计算差值
Calendar xmas = new GregorianCalendar(2004, Calendar.DECEMBER, 25);
Calendar newyears = new GregorianCalendar(2005, Calendar.JANUARY, 1);
// 相差毫秒数
long diffMillis = newyears.getTimeInMillis()-xmas.getTimeInMillis();
// 相差秒数
long diffSecs = diffMillis/(1000);
// 相差分数
long diffMins = diffMillis/(60*1000);
// 相差小时数
long diffHours = diffMillis/(60*60*1000);
// 相差天数
long diffDays = diffMillis/(24*60*60*1000);
3.
Calendar xmas = new GregorianCalendar(2004, Calendar.DECEMBER, 25);
Calendar newyears = new GregorianCalendar(2005, Calendar.JANUARY, 1);
long average= (xmas.getTimeInMillis()+newyears.getTimeInMillis)/2;