zoukankan      html  css  js  c++  java
  • Yii2 rules 添加时间比较功能

    php比较类文件:yiisoftyii2validatorsCompareValidator.php

    JS比较类文件: yiisoftyii2assetsyii.validation.js

    原来的比较 只包含integer 和 string 两种情况

    通过添加类型 来增加时间的比较

    前台用的是js时间选择插件 时间格式为 YYYY-hh-dd hh:ii:ss 之类的

    PHP中用的是转换为时间戳比较时间   strtotime()

    JS中 用的是 new Date() 比较时间(一定要 new 否则可能出问题)

    
    

    // safari 浏览器 只能 new Date('yyyy/mm/dd')
    function formatDate(value)
    {
      value = value.split('-');
      if(value.length < 3) value.push('01');
      return value.join('/');
    }


    if
    (options.type === 'number') { value = parseFloat(value); compareValue = parseFloat(compareValue); }else if(options.type === 'strtotime'){ // 这里是新添加的 //value = new Date(value); // compareValue = new Date(compareValue);

          value = new Date(formatDate(value));
          compareValue = new Date(formatDate(compareValue));

    
    }
    if ($type === 'number') {
        $value = (float) $value;
        $compareValue = (float) $compareValue;
    }elseif($type === 'strtotime'){  // 这里是新添加的
        $value = strtotime($value);
        $compareValue = strtotime($compareValue);
    } else {
        $value = (string) $value;
        $compareValue = (string) $compareValue;
    }

    更新JS文件后 一定要删除缓存哦!

  • 相关阅读:
    sql server拆分字符串
    Pivot 和 UnPivot 实现行列转换
    SQL快速生成连续整数
    Sql Server水平分区
    各种排序算法的C语言实现
    JWT 与 Token 介绍
    python接口自动化-token关联登录
    CUDA刷新器:CUDA编程模型
    利用MONAI加速医学影像学的深度学习研究
    构建可扩展的GPU加速应用程序(NVIDIA HPC)
  • 原文地址:https://www.cnblogs.com/cgjcgs/p/6050420.html
Copyright © 2011-2022 走看看