1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to Display Current Time (hh:mm)

Discussion in 'PHP' started by ademmeda, May 11, 2011.

  1. #1
    Hi,

    I want to display current time on a web page in this format hh:mm (like 19:07)

    Only hour and minute. How can I do this?
     
    ademmeda, May 11, 2011 IP
  2. Jane Management

    Jane Management Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    date("H:i", time());
    PHP:
     
    Jane Management, May 11, 2011 IP
  3. samie

    samie Member

    Messages:
    269
    Likes Received:
    8
    Best Answers:
    1
    Trophy Points:
    45
    #3
    Yep :) You got this covered.

    So if you wanted to display the time on the page then i would be:
    <?php echo date("H:i", time()); ?>

    If you wanted to put in into a variable you should be able to do:
    <?php $currentTime = date("H:i", time()); ?>

    Then you could just put it in a database or do whatever you wanted with it.
     
    samie, May 11, 2011 IP
    ademmeda likes this.
  4. bogi

    bogi Well-Known Member

    Messages:
    482
    Likes Received:
    16
    Best Answers:
    2
    Trophy Points:
    140
    #4
    bogi, May 11, 2011 IP
  5. ademmeda

    ademmeda Active Member

    Messages:
    354
    Likes Received:
    3
    Best Answers:
    3
    Trophy Points:
    70
    #5
    Thanks all, I guess I should have visited http://tr.php.net/manual/en/function.date.php before asking. But we all are here to ask and learn, right? I also learned strtotime() function which allows to get the timezone difference into account. Here is the function I'm using now:

    date('Y.m.d, H:i', strtotime('now + 3 hours'))
    PHP:
     
    ademmeda, May 12, 2011 IP