php - Setting a greeting based on user's time (Good morning, good afternoon…) -
Whether any extrapolation to implement "good evening" or "good morning" based on user's settings Can do?
Perhaps the PHP server will get time, but I want to welcome site visitors with a timely-based greeting that understands their time of day.
EG: Good morning, good night, good afternoon
Place it on the .getHours ()
on the date. Javascript's date object will use the user's local time instead of server-time:
var now = new date (); Alerts (now .hosthors ());
Some conditional checks, and you are in business. For example, the following is a very simple and easy-to-understand example:
var now = new date (); Var Hers = now Guesthors (); Var Message = ""; If (hours> 0) msg = "Morning Sunshine!"; // Actually if initial (hours> 6) msg = "good morning"; // If after 6 o'clock (hours> 12) msg = "Good Off"; // 12pm after (hours> 17) msg = "good evening"; // 5pm after (hours> 22) msg = "go to bed!"; // 10 pm after alert;
It's currently 2:56 pm, so I look at "Morning Sunshine"! You can test your local time with this online demo when I run it:
Comments
Post a Comment