Convert to date format dd/mm/yyyy

前端 未结 6 926
感动是毒
感动是毒 2020-12-01 06:29

I have the following date: 2010-04-19 18:31:27. I would like to convert this date to the dd/mm/yyyy format.

相关标签:
6条回答
  • 2020-12-01 06:44

    You can use a regular expression or some manual string fiddling, but I think I prefer:

    date("d/m/Y", strtotime($str));
    
    0 讨论(0)
  • 2020-12-01 06:54
    <?php
    $test1='2010-04-19 18:31:27';
    echo date('d/m/Y',strtotime($test1));
    ?>
    

    try this

    0 讨论(0)
  • 2020-12-01 07:03

    Try this:

    $old_date = Date_create("2010-04-19 18:31:27");
    $new_date = Date_format($old_date, "d/m/Y");
    
    0 讨论(0)
  • 2020-12-01 07:05

    There is also the DateTime object if you want to go that way: http://www.php.net/manual/en/datetime.construct.php

    0 讨论(0)
  • 2020-12-01 07:07

    If your date is in the format of a string use the explode function

        array explode ( string $delimiter , string $string [, int $limit ] )
    //In the case of your code
    
    $length = strrpos($oldDate," ");
    $newDate = explode( "-" , substr($oldDate,$length));
    $output = $newDate[2]."/".$newDate[1]."/".$newDate[0];
    

    Hope the above works now

    0 讨论(0)
  • 2020-12-01 07:07
    $source    =    'your varible name';
    $date    =     new DateTime($source);
    $_REQUEST["date"]    =     $date->format('d-m-Y');
    
    echo $_REQUEST["date"];
    
    0 讨论(0)
提交回复
热议问题