Search code examples
cstrftime

Display Month in Spanish using strftime?


I am trying to get the format a date from 2018-09-01 to September 1, 2018. I have been using:

strftime(displayDate, sizeof(displayDate), "%B %d %Y", &date_obj);

It works perfectly, but, is there a way to format the Month to be in Spanish?


Solution

  • The strftime function formats dates based on the current locale. So you'll need to set the locale for LC_TIME first:

    setlocale(LC_TIME, "es_ES-UTF_8");
    

    See setlocale for more information.