正确的方法来为您在的Flex /的Actionscript空日期?您在、来为、正确、日期

2023-09-08 15:24:55 作者:花舞花落泪

在与日期工作()中的Flex / ActionScript对象,我使用下面的函数来检查空日期。这是正确的方式来检查空日期或是否有更好的选择了吗?

 公共职能IsDateNull(日期:日期):布尔
{
  如果(日期和放大器;&安培;!date.fullYear = 0)
  {
    返回true;
  }

  返回false;
}
 

解决方案

由于日期是一个扩展的对象,而不是一个原始类型它没有一个默认值,因此只应为空,如果它不是招'一类牛逼尚未被实例化。难道日期正从某种数据库映射或类似的规定的填充?否则,不只是

 如果(!为准)
 
Flash AS3 相对于AS2 新的特性和改动

 如果(日期== NULL)
 

没有必要有一个函数来做到这一点。对于DateField.selectedDate值应为NULL,如果没有日期已被选中呢。这是不是最初发布作为一个答案,因为我不完全理解所遇到的问题,这听起来好像有各种各样的情况下,虽然。根据不同的业务层和底层的JDBC(或其他连接器)将DB和DB类型上和数据类型的值会有所不同。一般而言,日期为null,直到内存是通过虽然调用构造函数收购了它。

谢谢, 肖恩

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

解决方案

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)

or

if(date==null)

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