Cobix web development

Hello please login or signup so you can benefit from the full FREE features of this forum!
Cobix web development

It doesn't matter if your the best or the worst web site designer, anybody is welcome here. Come on! Join in the fun.

    JavaScript dates

    Share

    mavrick368
    Begginer
    Begginer

    Posts: 14
    Cobix Points: 1334
    Reputation: 0
    Join date: 2009-11-02

    JavaScript dates

    Post by mavrick368 on Tue Nov 03, 2009 3:47 pm

    Create a Date Object

    The Date object is used to work with dates and times.

    The following code create a Date object called myDate:
    Code:
    var myDate=new Date()


    Note: The Date object will automatically hold the current date and time as its initial value!

    Set Dates

    We can easily manipulate the date by using the methods available for the Date object.

    In the example below we set a Date object to a specific date (14th January 2010):
    Code:
    var myDate=new Date();
    myDate.setFullYear(2010,0,14);


    And in the following example we set a Date object to be 5 days into the future:
    Code:
    var myDate=new Date();
    myDate.setDate(myDate.getDate()+5);


    Note: If adding five days to a date shifts the month or year, the changes are handled automatically by the Date object itself!
    Compare Two Dates


    The Date object is also used to compare two dates.

    The following example compares today's date with the 14th January 2010:
    Code:
    var myDate=new Date();
    myDate.setFullYear(2010,0,14);
    var today = new Date();

    if (myDate>today)
      {
      alert("Today is before 14th January 2010");
      }
    else
      {
      alert("Today is after 14th January 2010");
      }


    _______________________________
    CSS, HTML and PHP expert. Ask me?

    MoulantZ
    Fresh new coder
    Fresh new coder

    Posts: 8
    Cobix Points: 1320
    Reputation: 1
    Join date: 2009-11-02

    Re: JavaScript dates

    Post by MoulantZ on Tue Nov 03, 2009 3:53 pm

    me likes. thankyou for sharing


    _______________________________
    Присоединитесь ко мне поддерживающие русские на моем вебсайте. (Жаль я снял это некоторое время)

    mavrick368
    Begginer
    Begginer

    Posts: 14
    Cobix Points: 1334
    Reputation: 0
    Join date: 2009-11-02

    Re: JavaScript dates

    Post by mavrick368 on Tue Nov 03, 2009 3:56 pm

    No problem


    _______________________________
    CSS, HTML and PHP expert. Ask me?

      Current date/time is Fri Mar 12, 2010 9:19 pm