How to Print Current Time in PHP


Answers

  • April 21, 2020

    PHP has function time(), which will retruns current timestamp

    Check below code

    <?php

    $t=time();

    echo "Timestamp is: ".time(). ' and date and time is : '.date("Y-m-d H:i:s A",$t);
    echo '<br /><br />';

    date_default_timezone_set("UTC");

    $time = time();

    echo "UTC Timestamp is: ". time(). ' and date and time is : '.date("Y-m-d H:i:s A",$time);
    echo "<br /><br />";

    date_default_timezone_set("Asia/kolkata");

    echo "Asia/ kolkata Timestamp is: " .time(). ' and date and time is : '.date("Y-m-d H:i:s A",$t);
    echo "<br /><br />";

    ?>

     

    Output :

    Timestamp is: 1587493123 and date and time is : 2020-04-21 18:18:43 PM

    UTC Timestamp is: 1587493123 and date and time is : 2020-04-21 18:18:43 PM

    Asia/ kolkata Timestamp is: 1587493123 and date and time is : 2020-04-21 23:48:43 PM

     

    Comment

Have More Question?

Subscribe For Daily Updates

Flutter Questions
Android Questions