dongluanan7163
2017-04-29 13:07
浏览 20
已采纳

如何从PHP脚本通过CK Web Services将日期传递给CloudKit?

I am writing a PHP script to send data to a CloudKit database via CK Web Services. It works well with string data, but I am having trouble passing a date from PHP to a CK Date/Time field.

CK returns dates as a 13-digit TIMESTAMP. So, the following code

$timestamp = $record['created']['timestamp'];
$timestamp = $timestamp/1000;
echo '<td>'.date('m-d-Y H:i:s', $timestamp)."</td>";

echoes out

04-28-2017 12:35:19

Fine and dandy.

So I make the assumption that if CK delivers a 13-digit TIMESTAMP it should accept the same when passed to a Date/Time field.

Alas, passing $dobTimestamp from the following

$dobTimestamp = strtotime($dob) * 1000;

Results in this BAD_REQUEST error

Invalid value, expected type TIMESTAMP

When I go to the CK Dashboard and manually enter $dob, CK returns a value exactly equal to $dobTimestamp so I think passing $dobTimestamp should work . . . but it does not.

I cannot find out what I am supposed to do in Apple's docs. Does anyone know how to pass a date to a CK Date/Time field via Web Services? Hard to imagine there would not be a way to do it.

图片转代码服务由CSDN问答提供 功能建议

我正在编写一个PHP脚本,通过CK Web Services将数据发送到CloudKit数据库。 它适用于字符串数据,但是我无法将日期从PHP传递到CK日期/时间字段。

CK将日期返回为13位TIMESTAMP。 因此,以下代码

  $ timestamp = $ record ['created'] ['timestamp']; 
 $ timestamp = $ timestamp / 1000; 
echo'&lt;  td&gt;'。date('mdY H:i:s',$ timestamp)。“&lt; / td&gt;”; 
   
 
 

回声

04-28-2017 12:35:19

精细和花花公子。 \ n

所以我假设如果CK传递一个13位的TIMESTAMP,它应该在传递给日期/时间字段时接受它。

唉,传递 $ dobTimestamp 来自以下

  $ dobTimestamp = strtotime($ dob)* 1000; 
   
 
 

结果在此 BAD_REQUEST 错误

无效值,预期类型TIMESTAMP

当我转到CK Dashboard并手动输入 $ dob 时,CK返回一个完全等于 $ dobTimestamp 的值,所以我认为传递 $ dobTimestamp 应该管用 。 。 。 但它没有。

我无法找到我应该在Apple的文档中做什么。 有谁知道如何通过Web服务将日期传递给CK日期/时间字段? 很难想象没有办法做到这一点。

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douben7493 2017-06-04 15:36
    已采纳

    After a lot of fiddles, here's what works using PHP DateTime:

    $openingDate = $_POST['openingDate']; // is mm/dd/yyyy
    $closingDate = $_POST['closingDate'];
    

    . . .

    // Process Dates
    $openingDateTime = new DateTime($openingDate, new DateTimeZone('America/New_York'));  // Create new DateTime object
    $closingDateTime = new DateTime($closingDate, new DateTimeZone('America/New_York'));
    
    date_time_set($openingDateTime, 10, 00); // Set time for date object
    date_time_set($closingDateTime, 17, 00); // Set time for date object
    
    $oDate = (date_timestamp_get($openingDateTime)*1000);  // Get the TIMESTAMP from DateTiem object and convert to milliseconds
    $cDate  = (date_timestamp_get($closingDateTime)*1000);
    

    The JSON for the CK Query is simple:

    . . .

    "openingDate": {"value":'.$oDate.'}, 
    "closingDate": {"value":'.$cDate.'}, 
    
    打赏 评论

相关推荐 更多相似问题