How do you Write/Display Time and Date in JavaScript?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • patelxxx
    New Member
    • May 2007
    • 135

    How do you Write/Display Time and Date in JavaScript?

    However not using document.write! !

    Cheers
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    You can set the innerHTML property of an element to the time and date.

    How do you wish to display the time and date and when (during or after page load)?

    Comment

    • patelxxx
      New Member
      • May 2007
      • 135

      #3
      Format required: Tue Aug 07 12:02:05 2007
      and to be displayed after the page loads.

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        Originally posted by patelxxx
        Format required: Tue Aug 07 12:02:05 2007
        and to be displayed after the page loads.
        For formatting, you can do it yourself using the Date object or just use a library.

        Use a div:
        [HTML]<div id="displayDate Time"></div>[/HTML] and whenever you require the date/time to be displayed, format the current date/time and display using:
        [CODE=javascript]document.getEle mentById("displ ayDateTime").in nerHTML=formatt eddate;[/CODE]

        Comment

        • patelxxx
          New Member
          • May 2007
          • 135

          #5
          Do I have make a function from:
          document.getEle mentById("displ ayDateTime").in nerHTML=formatt eddate;

          Because I tried placing this within <SCRIPT> tag and it never worked? I did place the <DIV> tag in the <BODY> section.

          Where am I going wrong? Sorry quite new to Javascript!!

          Comment

          • iam_clint
            Recognized Expert Top Contributor
            • Jul 2006
            • 1207

            #6
            formatteddate you need this to actually be your formatted date
            [CODE=javascript]
            var formatteddate = new Date();
            formatteddate = formatteddate.f ormat('M jS, Y');
            [/CODE]

            Please refer to this Link

            Comment

            Working...