:如何验证日期,以便我做出<code>DateField</code>必须来到今天的日期后的DateField黑莓
DateField date=new DateField("Date : ",System.currentTimeMillis(),DateField.DATE_TIME);
如何验证日期的输入必须来到今天日期后?我不知道如何从datefield获取值。
在此先感谢
:如何验证日期,以便我做出<code>DateField</code>必须来到今天的日期后的DateField黑莓
DateField date=new DateField("Date : ",System.currentTimeMillis(),DateField.DATE_TIME);
如何验证日期的输入必须来到今天日期后?我不知道如何从datefield获取值。
在此先感谢
也许是这样的:
if(date.getDate() < Calendar.getInstance().getTimeInMillis())
{
// Do whatever
}
Calendar.getInstance()。getTimeInMillis(); getTimeInMillis()无法使用 – 2014-11-04 17:29:10
您需要添加更多代码并提供有关您需要解决的问题的更详细说明。没有足够的信息为您的问题提供有意义的解决方案。 – hfontanez 2014-11-04 19:46:14
您可以使用date.getDate()返回输入的日期/时间以毫秒为单位(时代)
long inputDate = date.getDate() ;
// Then you can get current date/time in milliseconds with :
Date now = new Date() ;
long currentDate = now.getTime() ;
if (inputDate > currentDate)
{
// valid input in future
}
“我不知道如何从datefield获取值。“ DateField类具有getter方法getDate()。它返回一个“长”。 'System.currentTimeMillis()'也返回一个'long'。我在这里误解了什么吗? – hfontanez 2014-11-04 14:28:31
亚这就是问题,我使用getDate但它是一个长类型,什么即时通讯如果我可以从datefield得到的值,然后我可以比较今天的日期(使用calendar.getInstance()) – 2014-11-04 14:57:08
为什么你想这样做? 'System.currentTimeMillis()'以毫秒为单位给你当前的日期/时间。将DateField上设置的值与从系统获取的当前时间进行比较。 – hfontanez 2014-11-04 15:28:36