在java中获取最大日期值的最佳方式? [英] Best way to get maximum Date value in java?

查看:2410
本文介绍了在java中获取最大日期值的最佳方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一些逻辑,需要将null日期视为永远在将来(有关日期是有效期,可能存在或可能不存在)。而不是在整个代码中放置一个空日期的特殊情况,我只想将null转换为最大可能的日期。我没有看到任何明显的方式来获得这样的价值,没有硬编码。获取使用Date实现的最大值的最佳方式是什么?

解决方案

尝试

 新日期(Long.MAX_VALUE)

它应该给你Java中最长的日期值。


I'm writing a bit of logic that requires treating null dates as meaning forever in the future (the date in question is an expiration date, which may or may not exist). Instead of putting in special cases for a null date throughout the code, I want to just convert null into the maximum possible Date. I don't see any obvious ways to get such a value without hard coding it. What's the best way to get the maximum value of whatever Date implementation is being used?

解决方案

Try

new Date(Long.MAX_VALUE)

which should give you the longest possible date value in Java.

这篇关于在java中获取最大日期值的最佳方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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