How to determine the first day of week in python

后端 未结 4 1923
清歌不尽
清歌不尽 2021-01-15 13:08

Based on the locale I need to find what is the first day of the week (Sunday/Monday) In JAVA I would do:

Calendar FR_cal = Calendar.getInstance(Locale.FRANCE         


        
4条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-15 13:39

    This functionality seems to be missing from the python standard library up to and including (at least) Python 3.1.2.


    Some clues:

    Since information about this is usually stored along with the systems l10n data (in the GNU world that would be the locale def's likely in /usr/share/i18n/locales/) my first reaction was to use something like locale.nl_langinfo(), but unfortunately there is nothing like locale.FIRST_WEEKDAY in the locale module :-(

    Aside from the Babel lib mention by aaronasterling, I found this example of a solution for the named problem used inside a GNOME applet. Also worth noting is the accompanying blog post.

提交回复
热议问题