分类 默认分类 下的文章

比如要显示:XXX天后过期,XXX小时前已过期
使用时用 diffDate 方法

...


    public static function diffDate($timestampNow, $timestamp, $returnTimestamp = false, $level=0, $lang='zh')
    {
        if (!is_numeric($timestampNow)) $timestampNow = strtotime($timestampNow);
        if (!is_numeric($timestamp)) $timestamp = strtotime($timestamp);
        if ($timestamp > $timestampNow) $append = '后';
        elseif ($timestamp < $timestampNow) $append = '前';
        $diffTimestamp = $timestampNow - $timestamp;
        if ($returnTimestamp) return $diffTimestamp;
        $diffTimestamp = abs($diffTimestamp);
        if ($diffTimestamp > 86400) $level = 3;
        elseif ($diffTimestamp > 3600) $level = 2;
        else $level = 1;
        return self::timeLength($diffTimestamp, $lang, $level) . $append;
    }


    /**
     * 时长人性化显示
     * @param $second
     * @param $lang
     * @param int $level 返回的最小单位,0秒,1分,2时,3天
     * @return string
     */
    public static function timeLength($second, $lang='zh', $level=0)
    {
        $arr = [
            'zh'=>['天'=>'天','小时'=>'小时','分'=>'分',''=>'','秒'=>'秒',],
            'en'=>['天'=>'d','小时'=>'h','分'=>'m',''=>'','秒'=>'s',],
        ];
        $second = (int)$second;
        if ($second <=0 ) $second=0;
        $text = [];
        if ($level <= 3 && ($tmp1 = floor($second / 86400)) > 0) $text[] = "{$tmp1}{$arr[$lang]['天']}";
        if ($level <= 2 && ($tmp2 = floor(($second - $tmp1 * 86400) / 3600)) > 0) $text[] = "{$tmp2}{$arr[$lang]['小时']}";
        if ($level <= 1 && ($tmp3 = floor(($second - $tmp1 * 86400 - $tmp2 * 3600) / 60)) > 0) $text[] = "{$tmp3}{$arr[$lang]['分']}";
        if ($level <= 0 && ($tmp4 = $second % 60) > 0) $text[] = "{$tmp4}{$arr[$lang]['秒']}";
        return implode('', $text);
    }


    /**
     * 格式化时间戳
     * @param type $date
     * @return string
     */
    public static function formatTime($date) {
        $thisyear = intval(zmf::time(NULL, 'Y'));
        $dateyear = intval(zmf::time($date, 'Y'));
        if (($thisyear - $dateyear) > 0) {
            return zmf::time($date, 'Y-m-d H:i');
        }
        $thismo = intval(zmf::time(NULL, 'm'));
        $datemo = intval(zmf::time($date, 'm'));
        if ($thisyear == $dateyear && $thismo != $datemo) {
            return zmf::time($date, 'm-d H:i');
        }
        $timer = $date;
        $diff = zmf::now() - $timer;
        $thisto = intval(zmf::time(NULL, 'd'));
        $dateto = intval(zmf::time($date, 'd'));
        $day = $thisto - $dateto;
        $free = $diff % 86400;
        if ($day > 0) {
            if ($day > 7) {
                return zmf::time($date, 'n-j H:i');
            } elseif ($day == 1) {
                return "昨天 " . zmf::time($date, 'H:i');
            } elseif ($day == 2) {
                return "前天 " . zmf::time($date, 'H:i');
            } else {
                return $day . "天前";
            }
        } else {
            if ($free > 0) {
                $hour = floor($free / 3600);
                $free = $free % 3600;
                if ($hour > 0) {
                    return $hour . "小时前";
                } else {
                    if ($free > 0) {
                        $min = floor($free / 60);
                        $free = $free % 60;
                        if ($min > 0) {
                            return $min . "分钟前";
                        } else {
                            if ($free > 0) {
                                return $free . "秒前";
                            } else {
                                return '刚刚';
                            }
                        }
                    } else {
                        return '刚刚';
                    }
                }
            } else {
                return '刚刚';
            }
        }
    }


...

字符删除

x            删除光标所在处字符
X            删除光标所在前字符

单词删除

dw            删除到下一个单词开头
de            删除到本单词末尾
dE            删除到本单词末尾包括标点在内
db            删除到前一个单词
dB            删除到前一个单词包括标点在内

行删除

dd            删除一整行
3dd           代表删除三行
D 或者 d$     删除光标位置到本行结尾
d0            删除光标位置到本行开头
d+方向键      删除光标行+上/下行

删除一大块好几行内容

shift+v             选择行,用方向键移动选择
ctrl+v              选择一个方形块,用方向键移动选择
dgg           删除光标到文件头所有内容
dG           删除光标到文件尾所有内容

按d删除的内容实际上是剪切的,可以按p进行粘贴回来

在chrome浏览器中点击文件上传后,弹出文件选择窗口,再用autoIt脚本执行中(脚本打包成exe文件)

WinActivate('打开')
ControlSetText("打开", "", "Edit1", $CmdLineRaw)
Sleep(30)
ControlClick("打开", "",  "Button1")

以上脚本的意义:
激活标题为“打开”的窗口
设置Edit1输入框中的值为 命令行传入的参数
点击【打开】按钮

如果脚本编辑时中文乱码,变成问号了,是编码问题
解决方法:File→Encoding→UTF-8

具体脚本语法参考中文文档:
https://www.wenjiangs.com/doc/autoit-winactivate

查看nginx访问日志分析恶意请求的时候,比如有人采集网站,网站有多个域名,不知道采集者使用的是哪个域名的时候可以增加host域名的记录

可以在nginx配置的http段log_format记录规则中增加 $http_host 的变量输出

map $http_x_forwarded_for  $clientRealIp {
    ""      $remote_addr;
    ~^(?P<firstAddr>[0-9\.]+),?.*$  $firstAddr;
}
log_format  main  'src:$clientRealIp cdn:$remote_addr $remote_user [$time_local] "$http_host $request" '
                  '$status $body_bytes_sent "$http_referer" '
                  '"$http_user_agent"';