how to change date format on this html user form

前端 未结 3 1550
抹茶落季
抹茶落季 2021-01-27 09:22

I have the html form which enter data into mysql DB, but in input field of date it has this format,

(mm/dd/yyyy) 

BUT I prefer to use this form

相关标签:
3条回答
  • 2021-01-27 09:55

    <script id="template" type="text/x-handlebars-template"> <table> <tr> <th>Posted on: </th> <td> <?php $date = '{{posted}}';</td> </tr> </table> </script> echo date('d M Y',strtotime($date));?>

    0 讨论(0)
  • 2021-01-27 10:05

    use this code

    $originalDate = "2010-03-21";
    $newDate = date("d-m-Y", strtotime($originalDate));
    
    0 讨论(0)
  • 2021-01-27 10:16

    You should be storing your dates as actual dates and not strings. You're only making your life more difficult by storing them in a non-standard format.

    But if you insist on using this format, this code will work for you:

    $original = DateTime::createFromFormat('m/d/Y', '04/18/1973');
    $date     = $original->format('d/m/Y');
    
    0 讨论(0)
提交回复
热议问题