...

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



dirtyglass
06-21-2009, 07:56 AM
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!
:confused:
Thanks for you help!

effpeetee
06-21-2009, 08:34 AM
Try this. It works for me.:D



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:-


<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.


<SCRIPT type="text/javascript">


greet();

</SCRIPT>



See the effect here. (http://exitfegs.co.uk/indexjscript.html)

Play around with it to get your exact result.

Frank

effpeetee
06-22-2009, 01:27 PM
I have just added to the code previously sent.

Frank

It's here again. (http://exitfegs.co.uk/indexjscript.html)

dirtyglass
06-23-2009, 04:15 AM
Fantastic - Thank you soo much for your help!! I appreciate it

Hsoutdoors
06-23-2009, 04:21 AM
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

effpeetee
06-23-2009, 12:13 PM
[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 (http://exitfegs.co.uk/indexjscript.html)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.


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

effpeetee
06-23-2009, 06:42 PM
I have put an amended version here. (http://exitfegs.co.uk/javaindex.html)

Veiw source, it's all there.

EDIT: See the following post.

Frank

Philip M
06-23-2009, 07:21 PM
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

effpeetee
06-23-2009, 08:02 PM
"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

Hsoutdoors
06-24-2009, 12:46 AM
Thanks.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum