I want to display a simple message based on user’s system time. For example, if the user current time is 10 AM then it will display Good Morning on the page and so on for >12 PM, >6 PM for Good evening message. I know it’s a very simple thing, but I am unable to get it working. I tried playing with currentTime but didn’t work. Can anyone from community guide me on how this can be achieved. Thank you!
Showing Morning, afternoon, evening, night message based on Time
Hello Hit,
take a look at this example…
https://russian-dima.wixsite.com/meinewebsite/date-time-onclick
And here you have the code for its functions…
var myTimer
export function BTNgetDate_click(event) {
const today = new Date();
let currentDate = today.toLocaleDateString()
$w('#TXTwindow').text = currentDate
}
export function BTNgetTime_click(event) {
const today = new Date();
let currentTime = today.toLocaleTimeString()
$w('#TXTwindow').text = currentTime
}
export function BTNsetTimer_click(event) {
myTimer = $w('#input1').value
console.log(myTimer)
$w('#input2').value = myTimer
}
export function BTNcheckTime_click(event) {
const today = new Date();
let currentTime = today.toLocaleTimeString()
if (currentTime<=myTimer) {
console.log("NO-ALARM")
$w('#TXTwindow').text = "NO-ALARM"
} else {
console.log("ALARM")
$w('#TXTwindow').text = "ALARM"
}
}
export function BTNconsoleLog_click(event) {
const today = new Date();
console.log(today)
console.log("DATE = " + today.toLocaleDateString())
console.log(typeof today.toLocaleDateString())
console.log("TIME = " + today.toLocaleTimeString())
console.log(typeof today.toLocaleTimeString())
console.log("------------------")
}
These are smal functions which shows you how you can get for example the current DATE and TIME. You can use it for your needs.
The last function shows just the console-log actions.
(Press F12 on your keyboard and go to CONSOLE when you are in your Google-Chrome-Browser)