为了账号安全,请及时绑定邮箱和手机立即绑定

将 strtotime 转换为整数

将 strtotime 转换为整数

PHP
慕哥6287543 2022-10-28 09:35:39
我正在尝试使用以下方法获取 -24 小时前的时间:$a = date('Y-m-d H:i:s', strtotime('-1 day', strtotime(date("Y-m-d H:i:s")))); $a = strtotime($a);计算得很好,但是当我使用变量$a发送到 API 时,它说该值不是整数。返回的错误是:400 Invalid 'Query' parameter: json: cannot unmarshal number into Go struct field SearchClause.ClauseChildren.RuleValue of type string如果我将变量更改为 this:$a = '1583751712';并将其发送到 API,它绝对可以正常工作。
查看完整描述

1 回答

?
素胚勾勒不出你

TA贡献1827条经验 获得超9个赞

发生错误是因为您API需要 astring而不是integer. 该函数strtotime返回timestamp as integer. 尝试将typecast您的整数转换为字符串。如前所述Sherif,如果您只需要返回时间戳,则不需要日期格式。

$a = (string) strtotime('-1 day');


查看完整回答
反对 回复 2022-10-28
  • 1 回答
  • 0 关注
  • 81 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号