How can I determine what day the week starts with in the current locale? I need this in C, presumably via the <time.h>
header. Thanks.

- 23,067
- 22
- 97
- 166
-
`ctime.h` isn't a standard library header file for the C language. Are you using C or C++. Correct either your question or your tags. – Mike Sherrill 'Cat Recall' Jul 05 '12 at 19:43
-
http://en.wikipedia.org/wiki/C_date_and_time_functions – Jul 05 '12 at 19:46
-
http://stackoverflow.com/a/275067/195488 – Jul 05 '12 at 19:49
-
@0A0D I don't see how the links you added help. – Dmitri Nesteruk Jul 05 '12 at 20:01
-
1POSIX locales do not provide this information. – n. m. could be an AI Jul 05 '12 at 20:05
-
@n.m. okay, so what are my options? if I use C++ instead of C, is there anything else I can use? (assume that using 3rd-party libs like boost is not possible) – Dmitri Nesteruk Jul 05 '12 at 21:10
-
Many applications let the user configure it. Google Calendar has a choice between Sunday, Monday and Saturday. I think Outlook has something similar too. – n. m. could be an AI Jul 06 '12 at 08:48
-
possible duplicate of [How to determine which day is the first in week in current locale in C](http://stackoverflow.com/questions/11409902/how-to-determine-which-day-is-the-first-in-week-in-current-locale-in-c) – kapa Jul 12 '12 at 09:16
-
Look here http://stackoverflow.com/a/11410437/1321940 i had the same problem – Korniltsev Anatoly Jul 11 '12 at 08:12
1 Answers
Locales don't carry that information. That's because what "first day of the week" means depends on the application (on each application), not on the computer.
Where I work, some applications treat Monday as the first day of the week, and others treat Sunday as the first day of the week. Wall calendars here all use Sunday as the first day; manufacturing calendars usually use Monday.
Under Windows, use GetLocaleInfo(), but the locale can be changed at run time. It can be set through the Windows API. GetLocaleInfoEx() has more detailed documentation. It looks like SetLocaleInfo() can change the first day of the week independent of other locale settings.
Under Linux, there are provisions for identifying the first day of the week in the locale
utility. (man 5 locale
, or locale docs online. Search for "LC_TIME".) It's documented as conforming to POSIX.2, ISO/IEC 14652.
$ locale day
Sunday;Monday;Tuesday;Wednesday;Thursday;Friday;Saturday
First day of the week in my locale is Sunday.
I haven't yet been able to find a system call or library call for it. I don't have the source code handy.

- 91,602
- 17
- 122
- 185
-
1Yes, but countries *do* have information regarding which day is first. It's part of the operating system settings. Surely there's a way of getting at this information with some API? – Dmitri Nesteruk Jul 05 '12 at 22:21
-
-
-
@Catcall It is very bad that different applications use different "first day of the week", because it is confusing. It should be location or user preference dependent. In country where I live the first day of the week is Monday. When there is an application that fails to recognize this, things can get pretty confusing, especially for non-technical people who might not be familiar with this problem. – Alex Jul 06 '12 at 09:25
-
@Alex: When you have to coordinate manufacturing in multiple countries, you might have to cope with multiple first days of the week. I did. (And multi-national accounting is even worse.) – Mike Sherrill 'Cat Recall' Jul 06 '12 at 21:18