How to get the Day of the Week?

I assign the Date/Time with below commands. This works well.

var DateTime dStartTime = null
dStartTime = parse(now.getYear() + "-" + now.getMonthOfYear() + "-" + now.getDayOfMonth() + "T00:00")

With below string I get the format I can show in the Sitemap.
The only missing information is the Day of the Week.

How can I add for example “Saturday” for below output?

var String sStartTime = String::format(" - %02d.%02d.%02d %02d:%02d", dStartTime.getDayOfMonth() , dStartTime.getMonthOfYear(), dStartTime.getYear(), dStartTime.getHourOfDay(), dStartTime.getMinuteOfHour())

logInfo("Bewaesserung Rasen","Neuer Start Timer: " + sStartTime)

2020-04-03 18:52:36.503 [INFO ] [home.model.script.Bewaesserung Rasen] - Neuer Start Timer: - 04.04.2020 13:30

Did you try searching? :wink:

Hi Bruce,
I did search and also found several links. However this only worked for me when I used it in .items, but never when I defined a var in .rules
Seems I do something wrong :frowning:

Unsuprisingly, xxx.getDayOfWeek() returns the day as 1-7 from a Joda datetime.

Have you considered converting your timestamp to an epoch variable, and having java formatter use conversions like ‘A’ ?

1 Like

I got it running by converting DateTime to Joda and then to String.
Not sure this approach is to complex and I could achieve the same with a simpler step, but as least it works :slight_smile:

	val jStartTime = new DateTime((dStartTime as DateTimeType).zonedDateTime.toInstant.toEpochMilli)
	logDebug("TEST","Start Date: " + jStartTime.toString("EEE yyyy-MM-dd'T'HH:mm:ss.SSSZ"))

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.