Add text between date and time - PHP

前端 未结 5 1506
我在风中等你
我在风中等你 2020-12-09 18:07

Is it possible to add text between date and time in PHP ?



This will create (07-06-2014 00:00)

5条回答
  •  生来不讨喜
    2020-12-09 18:34

    Derived from your example which you provided a bit late

    echo date('d-m-Y \a\t H:i:s') . ' hours';
    

    be sure to use the exact syntax given! Using double quotes " instead of single ones ' will result in you getting a tab for \t, you'd than need to use \\a\\t for proper syntax as in the example below:

    echo date("d-m-Y \\a\\t H:i:s") . ' hours';
    

    This is due to how php quoting works and has nothing to do with date formatting, things in ' don't get escaped while those in " do, so if you use " be sure to use double backslashes \\.

    If it's a datetime object

    echo $datetime->format('d-m-Y \a\t H:i:s') . ' hours';
    

    if you already have it as a string

    echo str_replace(' ', ' at ', $datetime) . ' hours';
    

提交回复
热议问题