例如:开始时间为 '2003-10-17 21:15:00'
结束时间为 '2003-10-17 21:30:00'
则开始实践和结束时间之间的差值为 15分钟
我的问题就是如何使用java方法计算得到 这个15分钟(使用sql语句也行)
请给出具体的实现方法,谢谢!!
结束时间为 '2003-10-17 21:30:00'
则开始实践和结束时间之间的差值为 15分钟
我的问题就是如何使用java方法计算得到 这个15分钟(使用sql语句也行)
请给出具体的实现方法,谢谢!!
解决方案 »
- 这程序为啥出现 java.lang.NullPointerException 错误??
- 关于System.in的一个很奇怪的问题
- 求<<java数据结构和算法>>第2版中的编程作业代码!
- 关于匹配完成后修改文件
- 请问throw 跳转和if else跳转的区别..在实际应用中?哪个更实际?
- ByteBuffer的疑问
- 用/* 。。。。*/注掉的javascript有沒有執行能力?
- 如何设计软件包的异常处理?
- 我需要解压在Unix下经过compress的文件,谁有相关的java资源,谢谢。
- java读取文本,插到mysql表中,出现问题。下标越界。
- Timer 问题
- 如何在第二个frame中改变第一个frame中的textfield显示?在线等
String t2="2005-6-8 21:25:44";
SimpleDateFormat formatter=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
ParsePosition pos = new ParsePosition(0);
Date d1 = formatter.parse(t1, pos);
pos = new ParsePosition(0);
Date d2 = formatter.parse(t2, pos);
long ms=d2.getTime()-d1.getTime();
System.out.println(ms/60000);
还有,ParsePosition pos = new ParsePosition(0); 这句话是什么意思,有何用处?
extends Object
ParsePosition is a simple class used by Format and its subclasses to keep track of the current position during parsing. The parseObject method in the various Format classes requires a ParsePosition object as an argument. By design, as you parse through a string with different formats, you can use the same ParsePosition, since the index parameter records the current position.
import java.text.ParseException;
import java.util.Date;class testDate{
public static void main(String[] args) throws Exception
{
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
dateFormat.setLenient(false);
Date date = dateFormat.parse("2005-05-24 09:00:00");
Date fdate=new Date();
//计算差值,你可以把3600000再除以60得到分钟
long l=(fdate.getTime()-date.getTime())/3600000;
System.out.println(l);
}
}
//java中取当前时间用java.util.Date就行了,不过最好进行一下时间格式的转换java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat("yyyy/MM/dd HH/mm/ss");
java.util.Date date=new java.util.Date();
System.out.println(formatter.format(date));
//最后建议楼主,如果要计算精确到秒的化,尽量直接用SQL写,因为如果插入数据是用数据库的系统时间的化,不能保证应用服务器和数据库的系统时间完全一致