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 vue3加ant-design-vue无法渲染出页面
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 路易威登官网 里边的参数逆向
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序