JavaScript - Display date

  • dschiltz
  • Born
  • Born
  • dschiltz
  • Posts: 2

Post 3+ Months Ago

I am new to JavaScript programming and need help getting my code to display correctly. Here is the code:

Code: [ Select ]
<HTML>
<HEAD>
    <TITLE>Fun with Phonics</TITLE>
<SCRIPT LANGUAGE="JAVASCRIPT">
<!--Hide from old browsers
    function chngSite() {
    alert("You are about to be transported to the new site location!")
    location = "http://www.scsite.com/"
    }
//-->
</SCRIPT>

</HEAD>
<BODY>
<CENTER><IMG SRC="fun.jpg" HSPACE=5 VSPACE=5 HEIGHT=64 WIDTH=129></CENTER>

<CENTER><HR Width="75%"></CENTER>
<SCRIPT LANGUAGE="JAVASCRIPT">
<!--Hide from old browsers
    document.bgColor="red"
    document.bgColor="white"
    document.bgColor="blue"
    document.bgColor="white"
    document.bgColor="green"
    document.bgColor="white"
    document.bgColor="blanchedalmond"
    var tNow = new Date()
    var tlocDate = tNow.toLocaleString()
    var tDate = tlocDate.substring(0,10)
    document.write("<H2><CENTER>Welcome, today is "+tDate+"</CENTER></H2>")
    var intro1 = "Hi, thanks for visiting our Web site, but we have moved. Please make a note "
    var intro2 = "of our new URL (http://www.funphonics.com) and notify the Webmaster about our new "
    var intro3 = "location. Click<A Href='http://www.scsite.com/'> here </A> or wait 15 seconds "
    var intro4 = "to be moved automatically to our new site."
    var introMsg = intro1+intro2+intro3+intro4
    document.write("<H4><FONT Color='firebrick'>"+introMsg+"</H4></FONT>")
    setTimeout("chngSite()",15000)
    document.write("<BR><H4><CENTER>This document was last modified "+document.lastModified+"</CENTER></H4>")


//-->
</SCRIPT>

</BODY>
</HTML>
  1. <HTML>
  2. <HEAD>
  3.     <TITLE>Fun with Phonics</TITLE>
  4. <SCRIPT LANGUAGE="JAVASCRIPT">
  5. <!--Hide from old browsers
  6.     function chngSite() {
  7.     alert("You are about to be transported to the new site location!")
  8.     location = "http://www.scsite.com/"
  9.     }
  10. //-->
  11. </SCRIPT>
  12. </HEAD>
  13. <BODY>
  14. <CENTER><IMG SRC="fun.jpg" HSPACE=5 VSPACE=5 HEIGHT=64 WIDTH=129></CENTER>
  15. <CENTER><HR Width="75%"></CENTER>
  16. <SCRIPT LANGUAGE="JAVASCRIPT">
  17. <!--Hide from old browsers
  18.     document.bgColor="red"
  19.     document.bgColor="white"
  20.     document.bgColor="blue"
  21.     document.bgColor="white"
  22.     document.bgColor="green"
  23.     document.bgColor="white"
  24.     document.bgColor="blanchedalmond"
  25.     var tNow = new Date()
  26.     var tlocDate = tNow.toLocaleString()
  27.     var tDate = tlocDate.substring(0,10)
  28.     document.write("<H2><CENTER>Welcome, today is "+tDate+"</CENTER></H2>")
  29.     var intro1 = "Hi, thanks for visiting our Web site, but we have moved. Please make a note "
  30.     var intro2 = "of our new URL (http://www.funphonics.com) and notify the Webmaster about our new "
  31.     var intro3 = "location. Click<A Href='http://www.scsite.com/'> here </A> or wait 15 seconds "
  32.     var intro4 = "to be moved automatically to our new site."
  33.     var introMsg = intro1+intro2+intro3+intro4
  34.     document.write("<H4><FONT Color='firebrick'>"+introMsg+"</H4></FONT>")
  35.     setTimeout("chngSite()",15000)
  36.     document.write("<BR><H4><CENTER>This document was last modified "+document.lastModified+"</CENTER></H4>")
  37. //-->
  38. </SCRIPT>
  39. </BODY>
  40. </HTML>


The problem I am having is in the document.write statement, it is supposed to display as "Welcome, today is 11/12/2008" instead mine displays as "Welcome, today is Wednesday,". What have I done wrong? Thanks for any help you can provide!!
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • RichB
  • Guru
  • Guru
  • User avatar
  • Posts: 1121
  • Loc: Boston

Post 3+ Months Ago

That actually worked in Opera 9.62, which is my usual browser, but not in IE or FF. Anyway, you can extract the individual parts of the date and stick them together again with concatenation:

Code: [ Select ]
var tNow = new Date()
var tDay = tNow.getDate()
var tMonth = tNow.getMonth()+1
var tYear = tNow.getFullYear()
document.write("<H2><CENTER>Welcome, today is " +tMonth+ "/" +tDay+ "/" +tYear+ "</CENTER></H2>")
  1. var tNow = new Date()
  2. var tDay = tNow.getDate()
  3. var tMonth = tNow.getMonth()+1
  4. var tYear = tNow.getFullYear()
  5. document.write("<H2><CENTER>Welcome, today is " +tMonth+ "/" +tDay+ "/" +tYear+ "</CENTER></H2>")
  • dschiltz
  • Born
  • Born
  • dschiltz
  • Posts: 2

Post 3+ Months Ago

Thank you -- I'll give that a try!

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 62 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.