简体   繁体   English

如何在PHP中创建UTC日期,可以使用getUTCFullYear()在javascript中对其进行解析

[英]How can I create UTC date in PHP which can be parsed in javascript using getUTCFullYear()

I am working with kimonolabs worldcup api. 我正在使用kimonolabs worldcup api。

Now the problem is while filtering with startTime field. 现在的问题是在使用startTime字段进行过滤时。 In the documentation the startTime field is defined as UTC DateTime . 文档中startTime字段定义为UTC DateTime

I have generated UTC datetime using PHP like: 我已经使用PHP生成了UTC日期时间,例如:

gmdate('Y-m-d\TH:i:s\Z', strtotime(date('Y-m-d H:i:s')));

But while running the filtering - the API gives as error saying: 但是在运行过滤时-API给出错误提示:

Object 2014-06-21T19:03:47Z has no method 'getUTCFullYear'

I believe that getUTCFullYear() is a javascript function which extracts four digit year value from a date object. 我相信getUTCFullYear()是一个JavaScript函数,可从日期对象中提取四位数的年份值。

My question is how can I generate a datetime format which will remove the error and give me data? 我的问题是如何生成日期时间格式以消除错误并提供数据?

My API call is like: 我的API调用类似于:

http://worldcup.kimonolabs.com/api/matches?status=Pre-game&startTime=2014-06-21T19:03:47Z

Thanks in advance for helping. 在此先感谢您的帮助。

I worked on building this API. 我致力于构建此API。 Mark is correct, the issue was on our end and not with the request you were making. 马克是正确的,问题出在我们这头上,而不是您提出的要求。 I've made some updates now so it should be able to handle any valid string that can be passed into the javascript Date constructor. 我现在进行了一些更新,因此它应该能够处理可以传递到javascript Date构造函数中的任何有效字符串。

I'm also not sure what exactly you wanted to use the date for, but it seemed unlikely that you wanted to look up matches by an exact timestamp. 我也不确定您要确切地使用该日期,但是您似乎不太希望按确切的时间戳查找比赛。 I thought it would be useful to add the ability to query on less than/greater than values. 我认为添加查询小于/大于值的功能将很有用。 For timestamps in particular this should allow you to do make much more practical queries. 特别是对于时间戳,这应该使您可以进行更实际的查询。

Here are some possible queries you can make now: 您现在可以进行以下查询:

/matches?startTime__lt=2014-06-21T19:03:47Z
/players?birthDate__gt=1990-12-12
/players?goals__gte=2

Hopefully this helps resolve the issues you were having with the API! 希望这有助于解决您在使用API​​时遇到的问题!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM