Convert epoch to a readable format

I have a rule that collects the data I need and stores it in these variables in these formats:

$WeatherLastRain = 2023-02-23T12:25:00.000Z
$WeatherLastLightning = 1677245080000

All I want to do is convert the variables into something like “Feb 23” and display it a readable date format on a tile or super tile.

I’ve been digging around here for a while but much of the info is about doing calculations on two different dates.

Have you read through the Date Functions in Rule Expressions help article?

The $WeatherLastLightning looks like it’s already in milliseconds, so it could be used with formatDate() directly:

formatDate(1677245080000, 'MMM D')

The $WeatherLastRain appears to be an ISO 8601 formatted date, so the formatDate() should be able to implicitly parse it as well.

myDate = "2023-02-23T12:25:00.000Z"
formatDate(myDate, 'MMM D')

Ok, that solved it for me. I ended up using a rule action to collect the dates and then another rule action to format the variable in a human readable format.

and

Thanks for your support!

I’m trying to do something similar, but with the hour and minute. So I’ve tried the below Action, but it sets the time incorrectly, at least for me. Do I need to add something for the time zone?

Which set the variable to:

Capture

The problem is that is not the time here. It’s 1 hour ahead.

If I enter the time stamp into the Epoch time stamp converter, I get the correct time:

Thoughts??

EDIT: So I’m thinking I need to subtract -14400 from the time stamp as it is retrieved. I just can’t seem to make it work in this expression…

FURTHER EXPLAINATION: What I’m trying to do is have the current time when the weather data is pulled. As an alternative, is it easier to somehow capture the time that the rule actually ran? That might be close enough.

It’s based on the timezone set for your location, so I would make sure that’s correct.

I would also try displaying more details in the formatted date for troubleshooting. (See the help article I linked above). I would also start by using a generic formatDate(TimeZone) so you get the raw ISO formatted time output to make sure you’re supplying a valid value.

Also, it’s not clear what the input value to your rule was as clearly the example shown in your $owTimeStamp expression is different than the input used in the Epoch timestamp converter as the times aren’t even close (not just a timezone issue, but clearly the minutes aren’t the same either, so it seems to be a different input value).

Keep in mind that the time formatting requires millisecond values whereas many APIs will respond with Unix timestamps which are in seconds. If you are getting a unix timestamp, you’ll need to make sure to multiple it by 1000 to get the relevant milliseconds for your input.

That’s because I spent hours trying different things. The images may have gotten mixed up.

Ugggh!!! After all that… that was the problem. It now works as intended; however, I’m doing it with 3 variables.

1st - (pulled from Open Weather with the other data)

2nd - Multiply by 1000

3rd - Format the time

I’ve tried to put this all in 1 neat expression but get an invalid expression result. Is this too much for 1 expression?

EDIT: I also added 5 second delays between setting variables because it seems sometimes it calculated the previous variable instead of the one being pulled. Not sure if that is possible though.

EDIT 2: Thanks for the help Josh.
This did it… much trial and error!!