Is there a way to determine the day of week (Mon, Tue, ...) within a custom app? Any idea where I'd find the methods available in the date class? I can't find that in any Hubitat documentation.
Thanks!
Have you tried the standard Groovy documentation? I am guessing it would probably be in there, assuming the calls are supported by Hubitat’s Groovy Sandbox.
Maybe something like this? Worth a try…
input "days", "enum", title: "Activate on these days", description: "Days to Activate", required:true, multiple:true, options: ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
...
if(days) {
def df = new java.text.SimpleDateFormat("EEEE")
df.setTimeZone(location.timeZone)
def day = df.format(new Date())
def dayCheck = days.contains(day)
if(dayCheck) {
state.daysMatch = true
} else {
state.daysMatch = false
}
}
Feel free to look through any of my code.
Have fun!
Thanks, everyone. From the stackoverflow link, these both worked:
def date = new Date()
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
def day = calendar.get(Calendar.DAY_OF_WEEK);
log.info "DOW: " + day // returns 4def date = new Date()
String DOW = date.format('EE')
log.info "DOW2: " + DOW // returns WED
@bptworld , Thanks, I'll try that, too!
Cheers!