在 Flex/Actionscript 中检查空日期的正确方法?
在 Flex/Actionscript 中使用 Date()
对象时,我使用以下函数来检查空日期。这是检查空日期的正确方法还是有更好的替代方法?
public function IsDateNull(date:Date):Boolean
{
if (date && date.fullYear != 0)
{
return true;
}
return false;
}
When working with Date()
objects in Flex/Actionscript, I'm using to following function to check for null dates. Is this the proper way to check for a null date or is there a better alternative out there?
public function IsDateNull(date:Date):Boolean
{
if (date && date.fullYear != 0)
{
return true;
}
return false;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于 Date 是一个扩展 Object 的类并且不是原始类型,因此它没有默认值,因此只有在尚未实例化时才应为 null。日期是从某种数据库映射还是类似的东西填充的?否则不只是
或
不需要有一个函数来做到这一点。对于 DateField.selectedDate,如果尚未选择日期,则该值应为 null。这最初并不是作为答案发布的,因为我不完全理解所遇到的问题,但听起来好像有多种情况。根据服务层和数据库的底层 JDBC(或其他连接器)以及数据库的类型和数据类型,这些值可能会有所不同。一般来说,Date 将为 null,直到通过调用构造函数为其获取内存为止。
谢谢,
肖恩
Since Date is a class that extends Object and isn't a primitive type it doesn't have a default value and therefore should only be null if it hasn't yet been instantiated. Is the Date being populated from some sort of database mapping or something along those lines? otherwise not just
or
no need to have a function to do this. For the DateField.selectedDate the value should be null if no date has been selected yet. This wasn't originally posted as an answer because I don't entirely understand the issue being encountered it sounds as though there's a variety of cases though. Depending on the service layer and underlying JDBC (or other connector) to the DB and the type of DB and datatype the values can vary. In general a Date will be null until memory is acquired for it through a call to the constructor though.
Thanks,
Shaun