duangang4001 2017-12-19 12:06
浏览 125
已采纳

php datetime-local格式替换你能帮帮我吗? [关闭]

can you please help me? i need to change

2017-12-31 11:45:00 

to

2017-12-31T11:45

using php function.

I need this datetime-local format for putting in a input value.

  • 写回答

2条回答 默认 最新

  • doutui8842 2017-12-19 12:19
    关注

    This might do it for you:

    <?php 
    $date = '2017-12-31 11:45:00';
    $newdate = date('Y-m-d\TH:i', strtotime($date));
    echo $newdate; // 2017-12-31T11:45
    ;?>
    

    Documentation about strtotime: http://php.net/manual/en/function.strtotime.php

    NOTE:

    strtotime max date is '19 Jan 2038 03:14:07 UTC'.

    New solution: PHP 5 >= 5.2.0, PHP 7

    Please consider to use the new DateTime function: http://php.net/manual/en/datetime.construct.php

    Example new DateTime:

    <?php
    
    $d = new DateTime("9999-12-31"); 
    $d->format("Y-m-d"); // "9999-12-31"
    
    $d = new DateTime("0000-12-31"); 
    $d->format("Y-m-d"); // "0000-12-31"
    
    $d = new DateTime("-9999-12-31"); 
    $d->format("Y-m-d"); // "-9999-12-31"
    
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办