Skip to content

Time Formatting Question #302

Answered by exetico
snbe82 asked this question in Q&A
Dec 19, 2022 · 4 comments · 5 replies
Discussion options

You must be logged in to vote

Hi

Thank you.

Is it just sensor.time, or something else?

The strftime is part of util not functions, so the utilities call should be to: util.date.strftime

utils.date.strftime expects a date object, but sensor.time only contains the time in the state key:

You'll have to create a valid date-string instead as pr. my knowledge. strftime is very light-weight, so you'll have to do just a bit with your own hands 😸 (and not as friendly as a solution like moment.js. We've used strftime to keep the package-size as low as possible.

You only have the timestamp in the sensor.time, so you'll need to help the library a bit for things to go as planned.

There's plenty of ways to do so, but here's a simp…

Replies: 4 comments 5 replies

Comment options

You must be logged in to vote
4 replies
@exetico
Comment options

@exetico
Comment options

@snbe82
Comment options

@exetico
Comment options

Answer selected by snbe82
Comment options

You must be logged in to vote
1 reply
@exetico
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants