Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    New to the CF scene
    Join Date
    Jun 2009
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    I am trying to add a greeting as in Good Morning / Good Evening after the time??

    Hi,

    I am trying to get the final result of my code to show:
    "The time is 23:20 Good Evening" or "The time is 6:00 Good Morning to my script but i just cant seem to get it ?? The code I have so far is:

    var d=new Date();
    var hours=d.getHours();
    var mins=d.getMinutes();

    document.write("The times is");
    if (mins<=9)
    {
    document.write (hours + ":0" + mins);
    }
    else
    {
    document.write (hours + ":" + mins);


    I have tried a few different ways but am stuck and they dont seem to work!

    Thanks for you help!

  • #2
    Senior Coder effpeetee's Avatar
    Join Date
    Feb 2007
    Location
    Clapham Junction - London SW
    Posts
    4,885
    Thanks
    228
    Thanked 204 Times in 203 Posts
    Try this. It works for me.
    Code:
     
     
      function greet() {
      var todaydate = new Date();
      var timeis = todaydate.getTime();
      todaydate.setTime(timeis);
      var houris = todaydate.getHours();
      if (houris >17) display = "Evening";
      else if (houris >11) display = "Afternoon";
      else display = "Morning";
      var title = document.title;
      var welcome = ("Good " + display + ". Welcome to the Taylor Website");
      document.write(welcome);
      }
     
    
      </script>
    
    also this:-
    
    
    Code:
    <script language="JavaScript">
    
    /*
    Plain English Time
    By Adam Brown (adambrown2@iname.com)
    For this script and more,
    Visit http://javascriptkit.com
    */
    
    function number(x) {
    if (x==1) return "one"; if (x==2) return "two"; if (x==3) return "three";
    if (x==4) return "four"; if (x==5) return "five"; if (x==6) return "six";
    if (x==7) return "seven"; if (x==8) return "eight"; if (x==9) return "nine";
    if (x==10) return "ten"; if (x==11) return "eleven"; if (x==12) return "twelve";
    return x; //default
    }
    function ishtime(h,m) {
    h = number(h)
    if (m<=3 || m>57) return h+" o'clock";
    if (m<=7)  return "five past "+h;
    if (m<=12) return "ten past "+h;
    if (m<=17) return "quarter past "+h;
    if (m<=23) return "twenty past "+h;
    if (m<=28) return "twenty-five past "+h;
    if (m<=33) return "half past "+h;
    if (m<=38) return "twenty-five to "+h;
    if (m<=43) return "twenty to "+h;
    if (m<=48) return "quarter to "+h;
    if (m<=53) return "ten to "+h;
    if (m<=58) return "five to "+h;
    return "h:m"; // never reached?
    }
    function daytime(h) {
    if (!h || h>21) return " at night"
    if (h<12) return " in the morning";
    if (h<=17) return " in the afternoon";
    return " in the evening"; // default
    }
    function ish(h,m) {
    if (!h && !m) { // if no time supplied, use the system time
    time = new Date()
    h = time.getHours()
    m = time.getMinutes()
    }
    z = daytime(h);
    h = h % 12 // fix to 12 hour clock
    if (m>57 && time.getSeconds()>30) m++; // round seconds
    if (m>60) m=0 // round up minutes
    if (m>33) h++ // round up hours
    if (h>12)  h = 1 // the clock turns round..
    if (h==0) h = 12
    return "It's now about "+ishtime(h,m)+z+"."
    }
    document.writeln(ish().fontcolor("black"),"<P>")
    
    </script>
    This goes into the markup where you want it to print.

    Code:
    <SCRIPT type="text/javascript">
    
    
     greet();
    
    </SCRIPT>

    See the effect here.

    Play around with it to get your exact result.

    Frank
    Last edited by effpeetee; 06-22-2009 at 12:24 PM.
    * Sources (updated: 21.11.2012.
    Using Windows 8 Professional. 64bit with HP Photosmart 5510 printer Very useful site here.

  • #3
    Senior Coder effpeetee's Avatar
    Join Date
    Feb 2007
    Location
    Clapham Junction - London SW
    Posts
    4,885
    Thanks
    228
    Thanked 204 Times in 203 Posts
    I have just added to the code previously sent.

    Frank

    It's here again.
    Last edited by effpeetee; 06-22-2009 at 12:36 PM.
    * Sources (updated: 21.11.2012.
    Using Windows 8 Professional. 64bit with HP Photosmart 5510 printer Very useful site here.

  • #4
    New to the CF scene
    Join Date
    Jun 2009
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Fantastic - Thank you soo much for your help!! I appreciate it

  • #5
    New to the CF scene
    Join Date
    Jun 2009
    Location
    Lansdale, PA
    Posts
    7
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Font

    How do you change font size and/or color to this code? I would like to replace the "Good ....." that I already have.

    Thanks in advance,

    Harry

    paoutdoors.synthasite.com

  • #6
    Senior Coder effpeetee's Avatar
    Join Date
    Feb 2007
    Location
    Clapham Junction - London SW
    Posts
    4,885
    Thanks
    228
    Thanked 204 Times in 203 Posts
    [QUOTE=Hsoutdoors;831511]How do you change font size and/or color to this code? I would like to replace the "Good ....." that I already have.

    Thanks in advance,

    Harry
    ===================================
    See it here with css in HEAD section.

    I actually use the header div to set the text size in my style sheet, but you can do it thus if you do not use a style sheet or a

    <style type="text/css">
    #header {
    background-color:#dd0;
    font-size:2.5em;
    color:#000;
    text-align:center;
    }
    </style>


    entry on your html page.

    Code:
      var title = document.title;
      var welcome = (display + " - Welcome to the Taylor Website");
      document.write(welcome);
    }
    -->
    </script>
    
    </head>
    
    <body>
      <div id="wrap">
        <div id="header">
    <h2><center>  --  Alter the <h2> to your choice. Remove the <center>, not needed
    
    <script language="JavaScript">
    /*
    Plain English Time
    By Adam Brown (adambrown2@iname.com)
    For this script and more,
    Visit http://javascriptkit.com
    */
    Frank
    Last edited by effpeetee; 06-23-2009 at 03:08 PM.
    * Sources (updated: 21.11.2012.
    Using Windows 8 Professional. 64bit with HP Photosmart 5510 printer Very useful site here.

  • Users who have thanked effpeetee for this post:

    Hsoutdoors (06-23-2009)

  • #7
    Senior Coder effpeetee's Avatar
    Join Date
    Feb 2007
    Location
    Clapham Junction - London SW
    Posts
    4,885
    Thanks
    228
    Thanked 204 Times in 203 Posts
    I have put an amended version here.

    Veiw source, it's all there.

    EDIT: See the following post.

    Frank
    Last edited by effpeetee; 06-23-2009 at 06:57 PM.
    * Sources (updated: 21.11.2012.
    Using Windows 8 Professional. 64bit with HP Photosmart 5510 printer Very useful site here.

  • #8
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    See http://www.codingforums.com/showthread.php?t=169971
    for comments on why fontcolor is not the right way.



    "It works for me" - Famous last words of inexperienced web-designer

  • #9
    Senior Coder effpeetee's Avatar
    Join Date
    Feb 2007
    Location
    Clapham Junction - London SW
    Posts
    4,885
    Thanks
    228
    Thanked 204 Times in 203 Posts
    "It works for me" - Famous last words of inexperienced web-designer
    Thanks for the testimonial.

    Judging by the commercial sites that I have viewed code. I must be in good company.

    Frank - alias effpeetee
    * Sources (updated: 21.11.2012.
    Using Windows 8 Professional. 64bit with HP Photosmart 5510 printer Very useful site here.

  • #10
    New to the CF scene
    Join Date
    Jun 2009
    Location
    Lansdale, PA
    Posts
    7
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Thanks.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •