duanjunao9348 2016-07-05 15:26
浏览 61
已采纳

添加1个月到零件字符串日期

wasnt sure how to best describe this. I make an API call and one of the elements I get back is like the following

0 => array:3 [▼
    "customId" => "12345"
    "customName" => "Month"
    "customValue" => "June 16"
]

As you can see the customValue is June 16, meaning June 2016. Is there any way I can add 1 month onto this, so to make it July 16? I know I could simply replace Jun with July using something like str_replace, but I do not want to change the expression month on month. What I am really looking for is to have the system understand that this is Jun 16 and 1 month needs adding onto it.

Would this be possible?

Thanks

  • 写回答

2条回答 默认 最新

  • doushi8231 2016-07-05 15:29
    关注

    To change the value of $monthAndDay:

    $monthAndDay = "June 16";
    $monthAndDay = date("F j", strtotime($monthAndDay." + 1 month"));
    
    echo $monthAndDay; //outputs July 16
    

    Within an array:

    $arr = [
        "customId" => "12345"
        "customName" => "Month"
        "customValue" => "June 16"
    ];
    
    $arr["customValue"] = date("F j", strtotime($arr["customValue"]." + 1 month"));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败