Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
344 views
in Technique[技术] by (71.8m points)

c - Determine what day of week the week starts with

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...