在 Flex/Actionscript 中检查空日期的正确方法? [英] Proper way to check for null dates in Flex/Actionscript?

查看:24
本文介绍了在 Flex/Actionscript 中检查空日期的正确方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Flex/Actionscript 中使用 Date() 对象时,我使用以下函数来检查空日期.这是检查空日期的正确方法还是有更好的替代方法?

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;
}

推荐答案

由于 Date 是一个扩展 Object 的类,并且不是原始类型,因此它没有默认值,因此只有在没有默认值时才应该为 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

if(!date)

if(date==null)

不需要有一个函数来做到这一点.对于 DateField.selectedDate,如果尚未选择日期,则该值应为 null.这最初不是作为答案发布的,因为我并不完全理解遇到的问题,但听起来好像有多种情况.根据服务层和底层 JDBC(或其他连接器)到 DB 以及 DB 的类型和数据类型,值可能会有所不同.通常,在通过调用构造函数为其获取内存之前,Date 将为空.

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.

谢谢,肖恩

这篇关于在 Flex/Actionscript 中检查空日期的正确方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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