String date current date/time?

后端 未结 6 1523
北恋
北恋 2021-02-19 00:51

I am using $date = date(\"D M d, Y G:i\");.

When I echo $date, it shows the correct date/time. Now I need this as an string.

I have tr

相关标签:
6条回答
  • 2021-02-19 01:00

    The date() function already returns a string.

    Doing this :

    $date = date("D M d, Y G:i");
    

    You'll have the current date in the $date variable, as a string -- no need for any additional operation.

    0 讨论(0)
  • 2021-02-19 01:05

    If you like working with objects you can do this:

    $date = new \DateTime('now');
    echo $date->format('D M d, Y G:i');
    
    0 讨论(0)
  • 2021-02-19 01:10

    With regards to:

    $today = strtotime($date); 
    

    Those numbers are the current timestamp (the number of seconds since January 1st 1970). You can use this as a second parameter in the date function to change the date to whatever you want.

    $newDate = date("D M d, Y G:i", $timeStamp);
    
    0 讨论(0)
  • 2021-02-19 01:15

    Your $date variable is a string, there's no need for any conversion.

    You can have a look at the documentation: http://ch.php.net/manual/en/function.date.php. The return value of the date() function is string.

    The strange numbers you see when you call strtotime() is the Unix timestamp which represents the number of seconds elapsed since January 1 1970 00:00:00 UTC.

    0 讨论(0)
  • 2021-02-19 01:19

    You're already getting a string. $date can be used like any string now.

    strtotime() actually gives you the number of seconds in time like unix

    0 讨论(0)
  • 2021-02-19 01:25
    $date = 'Today is '.date("D M d, Y G:i", time());
    echo $date;
    
    0 讨论(0)
提交回复
热议问题