douchui1657 2010-02-21 12:49
浏览 84
已采纳

在PHP中,如何在从iPhone InApp收据中检索的购买日期中添加3个月?

After I have validated the receipt against the App Store from my PHP server, the App Store sends me back a JSON response with

"status" : 0 
"receipt" : ( .... )

One of the receipt items is "purchase_date" which contains the following string (example) "2010-02-09 19:17:04 Etc/GMT"

I'm trying to establish a subscription service and would like to add 3 months to this date and then write that expiry date into a MySQL table.

Is there a string-to-date type function in PHP that can allow me to achieve the adding of 3 months?

I have found this example which looks like it adds 1 month to a date:

$date = date("Y-m-d");// current date
$date = strtotime(date("Y-m-d", strtotime($date)) . " +1 month");

But I'm not sure how I can turn the string passed by the App Store into a PHP recognised date.

  • 写回答

2条回答 默认 最新

  • doujinge9648 2010-02-21 12:53
    关注

    You have already done it, you just added one step too many.

    $purchase_date = "2010-02-09 19:17:04";
    $purchase_date_timestamp = strtotime($purchase_date);
    $purchase_date_3months = strtotime("+3 months", $purchase_date_timestamp);
    
    echo "Purchase date + 3months = ".date("Y-m-d h:i:s", $purchase_date_3months);
    

    this depends on strtotime recoginzing your time string - try it out first. But usually, strtotime can recognize any properly formatted anglo-american date/time string. If in doubt, check the manual.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题