Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
369 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 Reply

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...