javascript to display current date (and back dates)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kevin Gibbons

    javascript to display current date (and back dates)

    Hello all,

    I've browsed through past usenet archives, but can't seem to come
    across quite the javascript I'm looking for. I'm looking for a simple
    javascript that will display the date as such:

    May 17

    So basically, just displaying the current month and the current date.
    But I would also like the ability to backdate by one day, two days,
    etc.. So the next date might look as such:

    May 15

    Which would be two days earlier than today's date, but in keeping with
    the same format.

    Any help on this would be greatly appreciated.


    KG
  • kaeli

    #2
    Re: javascript to display current date (and back dates)

    In article <d8iga0ddt0c9dm k5bpc216vmtknh4 ik63i@4ax.com>, Kevin Gibbons
    <kevin@<NOSPAM> kgibbons.com> enlightened us with...[color=blue]
    > Hello all,
    >
    > I've browsed through past usenet archives, but can't seem to come
    > across quite the javascript I'm looking for. I'm looking for a simple
    > javascript that will display the date as such:
    >
    > May 17
    >[/color]

    If you're familiar with java's SimpleDateForma t class, you might like
    this author's javascript version.



    --
    --
    ~kaeli~
    Reading while sunbathing makes you well red.



    Comment

    • Mick White

      #3
      Re: javascript to display current date (and back dates)

      Kevin Gibbons <kevin@ wrote:
      I'm looking for a simple[color=blue]
      > javascript that will display the date as such:
      >
      > May 17
      >
      >I would also like the ability to backdate by one day, two days,
      > etc.. So the next date might look as such:
      >
      > May 15
      >
      >
      > Any help on this would be greatly appreciated.
      >[/color]

      m=
      ["Jan","Feb","Ma r","Apr","May", "Jun","Jul","Au g","Sep","Oct", "Nov","Dec"];
      n=new Date();
      today=m[n.getMonth()] +" "+n.getDate ();
      alert(today);

      n.setDate(n.get Date()-2);
      dayBeforeYester day=m[n.getMonth()]+" " +n.getDate();
      alert(dayBefore Yesterday);

      Something like that.
      Mick

      Comment

      • Dr John Stockton

        #4
        Re: javascript to display current date (and back dates)

        JRS: In article <d8iga0ddt0c9dm k5bpc216vmtknh4 ik63i@4ax.com>, seen in
        news:comp.lang. javascript, Kevin Gibbons <kevin@?.com> posted at Mon, 17
        May 2004 01:12:46 :
        [color=blue]
        >I've browsed through past usenet archives, but can't seem to come
        >across quite the javascript I'm looking for. I'm looking for a simple
        >javascript that will display the date as such:
        >
        >May 17[/color]

        Did you not find the FAQ of this newsgroup?
        Did you not find the FAQ of this newsgroup helpful?

        [color=blue]
        >So basically, just displaying the current month and the current date.
        >But I would also like the ability to backdate by one day, two days,
        >etc.. So the next date might look as such:
        >
        >May 15[/color]

        Not a good example; is May the name of the month, or the three-letter
        abbreviation therefor? A week earlier, should that be May 5 or May 05 ?

        Should the date be local-to-user, local-to-server, or GMT? I assume the
        former, and that the user's computer's clock can be believed.

        A = ["Jan", "Feb", "Mar", "Apr", "May", ..., "Dec"] // or "January" ..
        D = new Date()
        ITIS = A[D.getMonth()] + " " + D.getDate()
        D.setDate(D.get Date() - 2)
        TWAS = A[D.getMonth()] + " " + D.getDate()

        That gives May 5 style; for May 05 use LZ(D.getDate()) with

        function LZ(x) { return (x<0||x>=10?"": "0") + x }


        <FAQENTRY>
        IMHO, typing would be saved if LZ were in the FAQ.
        </FAQENTRY>


        The following can be used for the current date IF you are assured that
        the first occurrence of <word> <space> <number> in String(new Date())
        will ALWAYS be what you want :-

        ITIS = String(new Date()).match(/(\w+ \d+)/)[1]

        --
        © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
        <URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
        <URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
        <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

        Comment

        Working...