检查变量数据返回日期对象

时间:2012-03-30 17:15:23

标签: jquery date

我有一个php函数,它返回一个包含数字的数组或一个日期字符串对象,我需要知道如何确定返回的是一个日期字符串对象,下面是代码示例

php功能

function dateTimerArr($timestamp){
   //only return date array if days is less than or equal to 31
   if(date("z", $timestamp)<=31){
      return array(
         's'=>intval(date("s", $timestamp)),    //seconds
         'i'=>intval(date("i", $timestamp)),        //min
         'H'=>intval(date("H", $timestamp)),        //hours
         'z'=>intval(date("z", $timestamp))     //days
      );
   }

   //otherwise return date 
   else{
      return date('d M Y | h:i A', $timestamp);
   }
}

jquery代码的一部分

success: function(data){
   if(/*if data is date string object*/){
      alert('date string object');
   }else{
      alert('in this case an array has been returned')
   }
}

1 个答案:

答案 0 :(得分:1)

使用jQuery的isPlainObject:

if ( !$.isPlainObject(data) ) {
    alert('date string object');
} else {
    alert('in this case an array has been returned')
}