{"id":1460,"date":"2016-07-13T10:44:24","date_gmt":"2016-07-13T10:44:24","guid":{"rendered":"http:\/\/javascript-tutor.net\/?p=1460"},"modified":"2017-09-21T13:35:09","modified_gmt":"2017-09-21T13:35:09","slug":"displaying-greeting-according-time","status":"publish","type":"post","link":"https:\/\/javascript-tutor.net\/index.php\/2016\/07\/13\/displaying-greeting-according-time\/","title":{"rendered":"Displaying greeting according to time"},"content":{"rendered":"<p>You can create a JavaScript to display greeting according to time. What you need to do is to create a new date object and use the getHours() method to fetch the time. Then use the if keyword to decide what greeting to display according to time. The script is a follows:<\/p>\n<p>CurDate=new Date();<br \/>\ntimeNow=CurDate.getHours();<br \/>\nvar greeting;<\/p>\n<p>if (timeNow&gt;18) {<br \/>\ngreeting=&#8217;Good Evening&#8217;;<br \/>\ngreeting=greeting.fontcolor(&#8220;red&#8221;);<br \/>\n} else if(timeNow&gt;12){<br \/>\ngreeting=&#8217;Good Afternoon&#8217;;<br \/>\ngreeting=greeting.fontcolor(&#8220;blue&#8221;);<\/p>\n<p>} else if(timeNow&gt;0) {<br \/>\ngreeting=&#8217;Good Morning&#8217;;<br \/>\ngreeting=greeting.fontcolor(&#8220;green&#8221;);<br \/>\n} else {<br \/>\ngreeting=&#8217;Good Day&#8217;;<br \/>\ngreeting=greeting.fontcolor(&#8220;cyn&#8221;);<br \/>\n}<br \/>\ngreeting=greeting.bold();<br \/>\ngreeting=greeting.fontsize(&#8220;10&#8221;);<br \/>\ngreeting=greeting.italics();<br \/>\ndocument.write(greeting);<\/p>\n<p>Click <a href=\"http:\/\/javascript-tutor.net\/jSample\/jscript_date2.html\">Here<\/a> to view the output<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You can create a JavaScript to display greeting according to time. What you need to do is to create a new date object and use the getHours() method to fetch the time. Then use the if keyword to decide what greeting to display according to time. The script is a follows: CurDate=new Date(); timeNow=CurDate.getHours(); var &hellip; <a href=\"https:\/\/javascript-tutor.net\/index.php\/2016\/07\/13\/displaying-greeting-according-time\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Displaying greeting according to time&#8221;<\/span><\/a><\/p>\n","protected":false},"author":35895,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1460","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Displaying greeting according to time - Learn JavaScript Online | Free Interactive JavaScript Tutorials<\/title>\n<meta name=\"description\" content=\"learn how to display greeting according to local time using JavaScript\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/javascript-tutor.net\/index.php\/2016\/07\/13\/displaying-greeting-according-time\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Displaying greeting according to time - Learn JavaScript Online | Free Interactive JavaScript Tutorials\" \/>\n<meta property=\"og:description\" content=\"learn how to display greeting according to local time using JavaScript\" \/>\n<meta property=\"og:url\" content=\"https:\/\/javascript-tutor.net\/index.php\/2016\/07\/13\/displaying-greeting-according-time\/\" \/>\n<meta property=\"og:site_name\" content=\"Learn JavaScript Online | Free Interactive JavaScript Tutorials\" \/>\n<meta property=\"article:published_time\" content=\"2016-07-13T10:44:24+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2017-09-21T13:35:09+00:00\" \/>\n<meta name=\"author\" content=\"Liew Voon Kiong\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Liew Voon Kiong\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/javascript-tutor.net\/index.php\/2016\/07\/13\/displaying-greeting-according-time\/\",\"url\":\"https:\/\/javascript-tutor.net\/index.php\/2016\/07\/13\/displaying-greeting-according-time\/\",\"name\":\"Displaying greeting according to time - Learn JavaScript Online | Free Interactive JavaScript Tutorials\",\"isPartOf\":{\"@id\":\"https:\/\/javascript-tutor.net\/#website\"},\"datePublished\":\"2016-07-13T10:44:24+00:00\",\"dateModified\":\"2017-09-21T13:35:09+00:00\",\"author\":{\"@id\":\"https:\/\/javascript-tutor.net\/#\/schema\/person\/63d832c3efdf443517b5f5bfd1b93df8\"},\"description\":\"learn how to display greeting according to local time using JavaScript\",\"breadcrumb\":{\"@id\":\"https:\/\/javascript-tutor.net\/index.php\/2016\/07\/13\/displaying-greeting-according-time\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/javascript-tutor.net\/index.php\/2016\/07\/13\/displaying-greeting-according-time\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/javascript-tutor.net\/index.php\/2016\/07\/13\/displaying-greeting-according-time\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/javascript-tutor.net\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Displaying greeting according to time\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/javascript-tutor.net\/#website\",\"url\":\"https:\/\/javascript-tutor.net\/\",\"name\":\"Learn JavaScript Online | Free Interactive JavaScript Tutorials\",\"description\":\"Master JavaScript with free, interactive tutorials for beginners and experienced coders. Practice live coding and visualize how JavaScript works step by step.\",\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/javascript-tutor.net\/#\/schema\/person\/63d832c3efdf443517b5f5bfd1b93df8\",\"name\":\"Liew Voon Kiong\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/javascript-tutor.net\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/413ad70576fa5f43c1d3ae3429c92579c21f536c350e6470302fa25ddd9b6a13?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/413ad70576fa5f43c1d3ae3429c92579c21f536c350e6470302fa25ddd9b6a13?s=96&d=mm&r=g\",\"caption\":\"Liew Voon Kiong\"},\"url\":\"https:\/\/javascript-tutor.net\/index.php\/author\/ajt7051jct\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Displaying greeting according to time - Learn JavaScript Online | Free Interactive JavaScript Tutorials","description":"learn how to display greeting according to local time using JavaScript","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/javascript-tutor.net\/index.php\/2016\/07\/13\/displaying-greeting-according-time\/","og_locale":"en_US","og_type":"article","og_title":"Displaying greeting according to time - Learn JavaScript Online | Free Interactive JavaScript Tutorials","og_description":"learn how to display greeting according to local time using JavaScript","og_url":"https:\/\/javascript-tutor.net\/index.php\/2016\/07\/13\/displaying-greeting-according-time\/","og_site_name":"Learn JavaScript Online | Free Interactive JavaScript Tutorials","article_published_time":"2016-07-13T10:44:24+00:00","article_modified_time":"2017-09-21T13:35:09+00:00","author":"Liew Voon Kiong","twitter_misc":{"Written by":"Liew Voon Kiong","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/javascript-tutor.net\/index.php\/2016\/07\/13\/displaying-greeting-according-time\/","url":"https:\/\/javascript-tutor.net\/index.php\/2016\/07\/13\/displaying-greeting-according-time\/","name":"Displaying greeting according to time - Learn JavaScript Online | Free Interactive JavaScript Tutorials","isPartOf":{"@id":"https:\/\/javascript-tutor.net\/#website"},"datePublished":"2016-07-13T10:44:24+00:00","dateModified":"2017-09-21T13:35:09+00:00","author":{"@id":"https:\/\/javascript-tutor.net\/#\/schema\/person\/63d832c3efdf443517b5f5bfd1b93df8"},"description":"learn how to display greeting according to local time using JavaScript","breadcrumb":{"@id":"https:\/\/javascript-tutor.net\/index.php\/2016\/07\/13\/displaying-greeting-according-time\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/javascript-tutor.net\/index.php\/2016\/07\/13\/displaying-greeting-according-time\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/javascript-tutor.net\/index.php\/2016\/07\/13\/displaying-greeting-according-time\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/javascript-tutor.net\/"},{"@type":"ListItem","position":2,"name":"Displaying greeting according to time"}]},{"@type":"WebSite","@id":"https:\/\/javascript-tutor.net\/#website","url":"https:\/\/javascript-tutor.net\/","name":"Learn JavaScript Online | Free Interactive JavaScript Tutorials","description":"Master JavaScript with free, interactive tutorials for beginners and experienced coders. Practice live coding and visualize how JavaScript works step by step.","inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/javascript-tutor.net\/#\/schema\/person\/63d832c3efdf443517b5f5bfd1b93df8","name":"Liew Voon Kiong","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/javascript-tutor.net\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/413ad70576fa5f43c1d3ae3429c92579c21f536c350e6470302fa25ddd9b6a13?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/413ad70576fa5f43c1d3ae3429c92579c21f536c350e6470302fa25ddd9b6a13?s=96&d=mm&r=g","caption":"Liew Voon Kiong"},"url":"https:\/\/javascript-tutor.net\/index.php\/author\/ajt7051jct\/"}]}},"_links":{"self":[{"href":"https:\/\/javascript-tutor.net\/index.php\/wp-json\/wp\/v2\/posts\/1460","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/javascript-tutor.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/javascript-tutor.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/javascript-tutor.net\/index.php\/wp-json\/wp\/v2\/users\/35895"}],"replies":[{"embeddable":true,"href":"https:\/\/javascript-tutor.net\/index.php\/wp-json\/wp\/v2\/comments?post=1460"}],"version-history":[{"count":4,"href":"https:\/\/javascript-tutor.net\/index.php\/wp-json\/wp\/v2\/posts\/1460\/revisions"}],"predecessor-version":[{"id":1524,"href":"https:\/\/javascript-tutor.net\/index.php\/wp-json\/wp\/v2\/posts\/1460\/revisions\/1524"}],"wp:attachment":[{"href":"https:\/\/javascript-tutor.net\/index.php\/wp-json\/wp\/v2\/media?parent=1460"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/javascript-tutor.net\/index.php\/wp-json\/wp\/v2\/categories?post=1460"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/javascript-tutor.net\/index.php\/wp-json\/wp\/v2\/tags?post=1460"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}