问题
I have a date and duration. I need to add the duration to date. Date's format is timestamp, duration's - Long (milliseconds). How can I wright criteria to deal this issue? Practically i have something like this: 03-17-2014 21:24:57 + 2523566;
回答1:
If you want to do it in Java and have a java.sql.Date and a long:
public java.sql.Date dateAdd(java.sql.Date inputDate, long duration)
{
return new java.sql.Date(inputDate.getTime() + duration);
}
A java.sql.Timestamp can be used in place of a java.sql.Date in either the argument or the return value, if required.
来源:https://stackoverflow.com/questions/25303635/cast-date-to-ms-to-add-long-value-of-duration-with-criteria