Type this card code into any page, with no other dependencies. It reads its date and time directly from Home Assistant, so it requires no integrations.
Card screenshot
TL/DR; Code only plz kthxbye
type: markdown
content: <center><h1>{{ now().strftime('%a %b %-d, %-I:%M %p')}}
Explanation for nerds
Gee, that sure looks ugly. What could it all mean?
- Center the date and time
<center>
- Not too bad. I don’t know what those funky characters are but OK.
- Make the text bigger
<h1>
- Is that HTML? I’m starting to have doubts.
- Start a template statement
{{
- Template? Uh-oh
- Get the current time, and provide it to the formatter
now().strftime('
- Good $deity WTF am I even looking at?!
- If you’re reading this far and this scares you, stop reading now! It only gets worse sorry!
- Format the date with non-breaking spaces
%a %b %-d
- I give up. Please stop!
- Example output: Wed Apr 24
- all
%
date formatters are described here
- Add a comma and a regular space
,
- Phew! THIS I understand!
- If you horizontally shrink or grow the page, this comma/space allows your browser to wrap between the date and the time.
- Format the date with non-breaking spaces and no leading zero for the hour
%-I:%M %p
- OMG again with this?!
- Example output: 10:42 AM
- all
%
time formatters are described here
- Terminate!
') }}
- Brain exploded
Notes
- If you use spaces in your date/time format instead of
, your web browser adds the line wrap in the wrong place- For example
Wed Apr 24, 10:42
linebreakAM
- IMHO the bad linebreak looks horrible, thus I pay the price of uglier formatters to avoid it!
- For example
- I am using USA-english. I assume the week days and months will use your local language. However I have not tested it.
EDIT: Variants
Version 1
I simplified: as_timestamp
is unnecessary. Also now I remove leading zero from the hour.
type: markdown
content: >-
<center><h1>{{ as_timestamp(now()) | timestamp_custom('%a %b %-d,
%I:%M %p') }}
Readability
Thanks for the suggestion @Taras. If the embedded
bother you, try this:
type: markdown
content: >-
<center><h1>{{ now().strftime('%a_%b_%-d, %I:%M_%p') | replace('_', ' ') }}