可能重复:
How to calculate the difference between two Java java.sql.Timestamps?
如何计算从Java中使用SQL获取的两个时间戳之间的年/月/日(实际上不需要时间)?
以下是我正在使用的代码片段:
query = "SELECT bc.periodbeginningdate " +
"FROM cus_billingcontract bc " +
"WHERE cus_billingcontract_id = " + recordID;
Timestamp bDate = DB.getSQLValueTS(null, query);
query = "SELECT bc.periodenddate " +
"FROM cus_billingcontract bc " +
"WHERE cus_billingcontract_id = " + recordID;
Timestamp eDate = DB.getSQLValueTS(null, query);
答案 0 :(得分:1)
您可以使用long
将时间戳转换为getTime()
:请点击此处查看大量信息:
How to calculate the difference between two Java java.sql.Timestamps?
然后,使用long
值,您可以使用JodaTime库轻松访问月差异。
见这里:
How to calculate difference ONLY in months using Java's Joda API