How can I find out what day the week starts for the current locale of the system?

Question:

It is required to display a calendar for a month in the console, for which it is necessary to know the day on which the week begins. In C, the default time structure stores the day of the week in the format 0-6, where 0 = Sunday. Interested in platform independence for this application. How to correctly get the system locale and find out the first day of the week for it? Perhaps there is a third-party cross-platform library, or will it have to be done under the API of different systems? You need to do it in pure C.

Answer:

Get the name of the current locale – setlocale(LC_ALL,NULL); . Instead LC_ALL you might be better off using LC_TIME .

Environment's default locale – setlocale(LC_ALL,"");

Current locale options – struct lconv *curloc = localeconv(); . Details in locale.h

In theory, you need to call setlocale(LC_TIME,""); and use localtime() , but in real life the problem is that the locale is often not set up properly.

Scroll to Top