将日期转换为ms,以便使用条件添加长时间的持续时间值 [英] cast date to ms to add long value of duration with criteria

查看:144
本文介绍了将日期转换为ms,以便使用条件添加长时间的持续时间值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个日期和持续时间。我需要添加迄今的持续时间。日期的格式是时间戳,持续时间 - 长(毫秒)。我该如何解决这个问题?
实际上我有这样的东西:
03-17-2014 21:24:57 + 2523566;

解决方案

如果你想用Java来完成它,并且有一个java.sql.Date和一个long:

  public java。 sql.date dateAdd(java.sql.Date inputDate,持续时间长)
{
return new java.sql.Date(inputDate.getTime()+ duration);
}

可以使用java.sql.Timestamp来代替java.sql 。如果需要,请在参数或返回值中使用日期。


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;

解决方案

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.

这篇关于将日期转换为ms,以便使用条件添加长时间的持续时间值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆