日度归档:2020年9月6日

php中如何将IP地址与长整型(long)之间相互转换呢?


摘要:
下文讲述php代码中IP地址同长整型(long)之间相互转换的方法分享,如下所示;

IP地址我们通常采用整型存储在数据库中,那么存储前,就需对其进行相应的转换,
下文讲述Php中IP地址与整型之间的转换方法,如下所示:

实现思路:
     ip地址转换为long 
       ip2long (IP —< long)
     
     long转换为ip地址
       long2ip (long —< ip)

例:


<?php
echo ip2long('192.168.8.10');
echo "\n";
echo ip2long('192.168.8.11'); 
echo "\n";
echo long2ip(3232237578);
echo "\n";
echo long2ip(3232237582);
echo "\n";
?>

输出:
3232237578
3232237579
192.168.8.10
192.168.8.14

MySQL如何根据秒数计算出所对应小时分钟数呢?


摘要:
下文讲述MySQL数据库计算出一个秒数所对应的小时数分钟数的方法分享,如下所示;

实现思路:
    使用SEC_TO_TIME函数即可返回秒数所对应的时间信息

SEC_TO_TIME语法:
      SEC_TO_TIME(seconds)
  --------参数说明-----
      seconds:
         秒数
  ---------返回值说明-----
  返回一个HH:MM:SS或HHMMSS格式的小时分钟信息
 

例:

mysql> select sec_to_time('a');
+------------------+
| sec_to_time('a') |
+------------------+
| 00:00:00         |
+------------------+
1 row in set, 1 warning (0.00 sec)

mysql> select sec_to_time('-121');
+---------------------+
| sec_to_time('-121') |
+---------------------+
| -00:02:01           |
+---------------------+
1 row in set (0.00 sec)

mysql> select sec_to_time('121');
+--------------------+
| sec_to_time('121') |
+--------------------+
| 00:02:01           |
+--------------------+
1 row in set (0.00 sec)

mysql> select sec_to_time('1211');
+---------------------+
| sec_to_time('1211') |
+---------------------+
| 00:20:11            |
+---------------------+
1 row in set (0.00 sec)

mysql> select sec_to_time('1211111');
+------------------------+
| sec_to_time('1211111') |
+------------------------+
| 336:25:11              |
+------------------------+
1 row in set (0.00 sec)

mysql> select sec_to_time('1211111111');
+---------------------------+
| sec_to_time('1211111111') |
+---------------------------+
| 838:59:59                 |
+---------------------------+
1 row in set, 1 warning (0.00 sec)

mysql> select sec_to_time('12111111111111');
+-------------------------------+
| sec_to_time('12111111111111') |
+-------------------------------+
| 838:59:59                     |
+-------------------------------+
1 row in set, 1 warning (0.00 sec)

mysql> select sec_to_time('1211111111111111111111');
+---------------------------------------+
| sec_to_time('1211111111111111111111') |
+---------------------------------------+
| -00:00:01                             |
+---------------------------------------+
1 row in set, 1 warning (0.00 sec)

linux 操作系统下如何查看文件的修改时间呢?


摘要:
下文讲述linux操作系统下查看文件最后修改时间的方法分享,如下所示;

查看Linux操作系统下文件的修改时间,是我们日常运维中常用的命令,
我们经常需查看文件的最后修改时间,那么如何实现这一功能呢?
下文将一一道来,如下所示:

实现思路:
  方式1:
     使用ls -l 或
         ls -ll 或
         ls --full-time
     命令即可查看文件的最后修改时间

  方式2:
     使用stat命令

例:

    
[root@maomao365.com local]# ls -ll
total 116
drwxr-xr-x. 10 root  root  4096 Aug  7 14:59 aegis
drwxr-xr-x.  2 root  root  4096 Nov 19  2014 bin
drwxr-xr-x   3 root  root  4096 Nov  1  2019 c
drwxr-xr-x.  2 root  root  4096 Nov 19  2014 etc
drwxr-xr-x.  2 root  root  4096 Sep 23  2011 games
drwxr-xr-x.  3 root  root  4096 Nov 19  2014 include
drwxr-xr-x.  4 root  root  4096 Apr 13  2015 lib
drwxr-xr-x.  2 root  root  4096 Sep 23  2011 lib64
drwxr-xr-x.  2 root  root  4096 Sep 23  2011 libexec
drwxr-xr-x   3 root  root  4096 Jan  4  2015 linuxYuanMa
drwxr-xr-x  11 mysql root  4096 Nov 26  2014 mysql
drwxr-xr-x   2 root  root 45056 Sep  6 21:53 mySqlBack
drwxr-xr-x  13 root  root  4096 Nov 11  2016 nginx
drwxr-xr-x   9 root  root  4096 Nov 27  2014 php
drwxr-xr-x.  2 root  root  4096 Sep 23  2011 sbin
drwxr-xr-x.  8 root  root  4096 Jul 28 17:01 share
drwxr-xr-x   2 root  root  4096 Aug 21  2015 shellStudy
drwxr-xr-x. 12 root  root  4096 Jul 13  2018 src


/*
Modify为修改时间
*/
[root@iZ23ji6c7snZ local]# stat *;
  File: `aegis'
  Size: 4096            Blocks: 8          IO Block: 4096   directory
Device: fc01h/64513d    Inode: 1063480     Links: 10
Access: (0755/drwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2020-09-06 17:35:20.044668053 +0800
Modify: 2020-08-07 14:59:51.845752690 +0800


[root@maomao365.com wordpress]# stat wp-cron.php
  File: `wp-cron.php'
  Size: 3669            Blocks: 8          IO Block: 4096   regular file
Device: fc01h/64513d    Inode: 1088161     Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2018-07-12 17:31:15.844100572 +0800
Modify: 2017-08-20 12:37:45.000000000 +0800
Change: 2018-07-12 17:28:18.382073475 +0800