i want to use date with a professional way

Discussion in 'PHP' started by moheballah, Sep 8, 2008.

  1. #1
    hi,

    i see a professional scripts allow you to define the way you want to display time of posts
    and allow member to define there time zone

    and so on

    how can i do this
    i want lesson to learn the best way to using date functions
     
    moheballah, Sep 8, 2008 IP
  2. Vooler

    Vooler Well-Known Member

    Messages:
    1,146
    Likes Received:
    64
    Best Answers:
    4
    Trophy Points:
    150
    #2
    Well, most of scripts store time in integer, the valued obtained rom function time() in php which provides the unix timestamp in form of seconds. Then passing the stored value to function date returns a formated date. e.g.

    $postdate = time();  #stored
    Code (markup):
    #now retrieving and formating
    $date = date("F d, Y",$postdate); #results something like September 9, 2008
    Code (markup):

    As far formatting as per timezone
    The timezone values are stored such as +5, -5, +4, +3 (HOURS).
    e.g. formatting as per timezone +5 hours

    $hours = 5;
    $postdate = $postdate + ($hours * 3600); #where 3600 is seconds of an hour
    $date = date("F d, Y",$postdate);
    Code (markup):

    I hope you have now an idea how it works.

    regards
     
    Vooler, Sep 9, 2008 IP
  3. mallorcahp

    mallorcahp Peon

    Messages:
    141
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    mallorcahp, Sep 9, 2008 IP