How do I use PHP to get the current year?

后端 未结 26 2226
萌比男神i
萌比男神i 2020-12-04 04:31

I want to put a copyright notice in the footer of a web site, but I think it\'s incredibly tacky for the year to be outdated.

How would I make the year update automat

相关标签:
26条回答
  • 2020-12-04 05:16

    http://us2.php.net/date

    echo date('Y');
    
    0 讨论(0)
  • 2020-12-04 05:16

    If your server supports Short Tags, or you use PHP 5.4, you can use:

    <?=date("Y")?>
    
    0 讨论(0)
  • 2020-12-04 05:17

    Here's what I do:

    <?php echo date("d-m-Y") ?>
    

    below is a bit of explanation of what it does:

    d = day
    m = month
    Y = year
    

    Y will gives you four digit (e.g. 1990) and y for two digit (e.g. 90)

    0 讨论(0)
  • 2020-12-04 05:17

    use a PHP date() function.

    and the format is just going to be Y. Capital Y is going to be a four digit year.

    <?php echo date("Y"); ?>
    
    0 讨论(0)
  • 2020-12-04 05:19

    BTW... there are a few proper ways how to display site copyright. Some people have tendency to make things redundant i.e.: Copyright © have both the same meaning. The important copyright parts are:

    **Symbol, Year, Author/Owner and Rights statement.** 
    

    Using PHP + HTML:

    <p id='copyright'>&copy; <?php echo date("Y"); ?> Company Name All Rights Reserved</p>
    

    or

    <p id='copyright'>&copy; <?php echo "2010-".date("Y"); ?> Company Name All Rights Reserved</p
    
    0 讨论(0)
  • 2020-12-04 05:20
    <?php
    $time_now=mktime(date('h')+5,date('i')+30,date('s'));
    $dateTime = date('d_m_Y   h:i:s A',$time_now);
    
    echo $dateTime;
    ?>
    
    0 讨论(0)
提交回复
热议问题