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.

  • 写回答

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.'}, 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 自适应 LMS 算法实现 FIR 最佳维纳滤波器matlab方案
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像