如何从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.

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

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

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

回声 p>

04-28-2017 12:35:19 p> blockquote>

精细和花花公子。 p> \ n

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

唉,传递 $ dobTimestamp code>来自以下 p>

  $ dobTimestamp = strtotime($ dob)* 1000; 
  code>  pre> 
 
 

结果在此 BAD_REQUEST code>错误 p>

无效值,预期类型TIMESTAMP p> blockquote>

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

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

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.'},