With glibc, you can do:
#define _GNU_SOURCE
#include <langinfo.h>
char get_first_weekday()
{
return *nl_langinfo(_NL_TIME_FIRST_WEEKDAY);
}
Remember to call setlocale()
first. Example:
#include <stdio.h>
#include <locale.h>
int main()
{
setlocale(LC_ALL, "");
printf("%d
", get_first_weekday());
return 0;
}
This returns 2
on my system (which means monday == DAY_2
).
Just a note: I don't think it's public API of glibc. However, this is how locale
tool bundled with it gets first weekday. cal
uses similar method as well.
Depending on a particular use, you may be interested in _NL_TIME_FIRST_WORKDAY
as well.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…