将 strtotime 转换为整数

我正在尝试使用以下方法获取 -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,它绝对可以正常工作。


慕哥6287543
浏览 82回答 1
1回答

素胚勾勒不出你

发生错误是因为您API需要 astring而不是integer. 该函数strtotime返回timestamp as integer. 尝试将typecast您的整数转换为字符串。如前所述Sherif,如果您只需要返回时间戳,则不需要日期格式。$a = (string) strtotime('-1 day');
打开App,查看更多内容
随时随地看视频慕课网APP