Issues with esptime example suggested by ChatGPT

I have a simple ESPHome system with a ESP32S2 and a ILI9341 TFT display.
This works fine, but I would like to print weekdays on the display translated into my native language.
I found this example from ChatGPT, but get an error message.

time:
  - platform: sntp
    id: time
    servers:
      - 0.pool.ntp.org
      - 1.pool.ntp.org
      - 2.pool.ntp.org

spi:
  clk_pin: D5
  mosi_pin: D7

display:
  - platform: ili9341
    model: TFT_2.4
    cs_pin: D8
    dc_pin: D3
    led_pin: D1
    reset_pin: D4
    rotation: 0
    lambda: |-
      static const char* days[] = {"Söndag", "Måndag", "Tisdag", "Onsdag", "Torsdag", "Fredag", "Lördag"};
      char buffer[50];
      auto now = id(time).now();
      sprintf(buffer, "Today is %s", days[now.day_of_week()]);
      it.printf(10, 10, id(font), "Hello World!");
      it.printf(10, 30, id(font), buffer);

This gives the error message:

**expression cannot be used as a function**
**           sprintf(buffer, "Today is %s", days[now.day_of_week()])**

I have also tried with esptime.now() instead of time, but this gives the same error message.??

Is there a similar way to translate months ??

You’re really better off going to the actual documentation then using something like ChatGPT that has been trained on several year old data and is incapable of actually knowing if it’s giving you correct answers or not.

There’s information in the documentation on how to use strftime to get the text of the day of the week or month, including information on how to make sure you get it back in your locale too. Specifically, there’s a link in the documentation to another site that tells you how to modify the parameters to get local language stuff back:

https://cplusplus.com/reference/ctime/strftime/

2 Likes

Thanks for a fast reply to my issue !

I already know how to get & print the time, date weekday etc in english (i have done that many times), and that works fine, but the problem is the translation of months & weekdays, and I cant find how to do that in the link you supplied,…
Can you please be a little more specific about where in the link content I can find this and how to use it (that would be a great help…)…

.

In that second link, scroll down and you’ll see the following text:

" Note: Yellow rows indicate specifiers and sub-specifiers introduced by C99. Since C99, two locale-specific modifiers can also be inserted between the percentage sign (% ) and the specifier proper to request an alternative format, where applicable"

Following those instructions should, in theory, give you the text in your local language.

I looked into this and tested, and unfortunately this does not seem to work for full weekday names or full month names…( using the suggested solution still presents them in english…)