【发布时间】:2019-06-29 02:20:53
【问题描述】:
在我的表单中,我没有选择日期,将该字段作为空传递,在数据库中它存储为空。在编辑期间,我正在检查该时间戳值是否为空,而打印该值为空。但是在使用 if 条件检查时它失败了。
为此,如果条件失败,我将时间戳与 null 和长度 ==0 进行比较。
if(session.getAttribute("deliveryDate").toString()!=null){
String delidate = session.getAttribute("deliveryDate").toString();
///////////////date convertion/////////////////
long unixSecondsfrom = Long.parseLong(delidate);
// convert seconds to milliseconds
Date datefrom = new java.util.Date(unixSecondsfrom);
// the format of your date
SimpleDateFormat sdffrom = new java.text.SimpleDateFormat("yyyy-MM-dd");
String formattedFromDate = sdffrom.format(datefrom);
///////////////date convertion/////////////////
page.set("deliveryDate", formattedFromDate);
}else{ page.set("deliveryDate", ""); }
当时间戳为空时,我需要上述条件为假,并且需要转到其他部分。
【问题讨论】:
-
toString绝不能返回null。 -
如果条件失败究竟是什么意思?它是否进入
else部分,是否进入错误的部分,是否引发异常,是否出现编译错误,还是什么? -
不,它不属于其他部分。我试过没有 toString()。