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.

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

在我从PHP服务器验证了App Store的收据后,App Store向我发送了一个JSON响应 with

 “status”:0 
“收据”:( ....)
   
 
 

一个 收据项目是“purchase_date”,其中包含以下字符串(示例)“2010-02-09 19:17:04 Etc / GMT”

我正在尝试建立订阅 服务,并希望在此日期添加3个月,然后将该到期日期写入MySQL表。

PHP中是否有一个字符串到日期类型的函数,可以让我实现3个月的添加?

我找到了这个例子,看起来它增加了1个月的日期:

  $ date = date(“Ymd”)  ; //当前日期
 $ date = strtotime(日期(“​​Ymd”,strtotime($ date))。“+ 1个月”); 
   
 
 

但是 我不确定如何将App Store传递的字符串转换为PHP识别日期。

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

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.

    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • duanjing9739 2010-02-21 18:25

    Don't treat time as a scalar value - It's much more complex than that. I would suggest that you push this logic into your database, provided that you use a one for storing data? Alternatively, recent versions of PHP has a datetime object, which can be used.

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题