我数据库l里时间格式为 2012-11-02 08:36:51 假设它为变量 $a 怎么换算成time()格式的,也就是这种 1362112369?求代码和解释说明,谢谢!
本意是让用户当时的时间减去之前他写入数据库时间,而得到一个数值,来判断一个行为
php,怎样把date("Y-m-d H:i:s ") 换算成time()结构
答案:4 悬赏:10
解决时间 2021-03-07 23:37
- 提问者网友:冰点阿弟
- 2021-03-07 08:49
最佳答案
- 二级知识专家网友:丢不掉的轻狂
- 2021-03-07 09:07
strtotime("2012-11-02 08:36:51");
这个是字符串转换成时间戳
数据库读出来就这样写
strtotime($rs['posttime']);
time()这个是输出当前时间的时间戳
strtotime还可以这样用,自己试试
echo(strtotime("now"));
echo(strtotime("3 October 2005"));
echo(strtotime("+5 hours"));
echo(strtotime("+1 week"));
echo(strtotime("+1 week 3 days 7 hours 5 seconds"));
echo(strtotime("next Monday"));
echo(strtotime("last Sunday"));
这个是字符串转换成时间戳
数据库读出来就这样写
strtotime($rs['posttime']);
time()这个是输出当前时间的时间戳
strtotime还可以这样用,自己试试
echo(strtotime("now"));
echo(strtotime("3 October 2005"));
echo(strtotime("+5 hours"));
echo(strtotime("+1 week"));
echo(strtotime("+1 week 3 days 7 hours 5 seconds"));
echo(strtotime("next Monday"));
echo(strtotime("last Sunday"));
全部回答
- 1楼网友:哭不代表软弱
- 2021-03-07 11:40
汗 那直接用replace()替换成你想要的得了 time()这是一个输出时间戳
- 2楼网友:情窦初殇
- 2021-03-07 10:56
string date ( string $format [, int $timestamp = time() ] )
第二个参数为时间戳,默认为当前的时间戳 即time()的返回值。
可以不填,但并不是无用的,他也并不是但为了显示秒数的,他是时间的时间戳表示。
你也可以指定时间戳 例如 date('y-m-d',time()+3600*24*10);//当前十天后
- 3楼网友:疯山鬼
- 2021-03-07 09:33
那个叫unix时间戳~
用strtotime()函数将某个函数转换为时间戳
你下个PHP中文手册,这东西写程序必备
www.ctdisk.com/shared/folder_2445186_e9c89f3f/
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯
• 手机登qq时,显示手机磁盘不足,清理后重新登 |
• 刺客的套装怎么选啊? |