Determine regional business days and weekend days of the week

倖福魔咒の 提交于 2019-12-13 06:32:30

问题


In some countries weekend days are Friday/Saturday.

How can a Windows application find out weekend days of the user?


回答1:


Wellll...I don't know of a "One function" answer to this. You're gonna need to know where they are somehow. If it's a webapp, you can trace their IP and figure out what country they are from. If it's a windows app, you're probably going to need to ask them (The clock only provides timezone information, and i can't figure out where else to grab a more fine-grained location from windows).

You can figure out what day it is with GetDayofWeek http://msdn.microsoft.com/en-us/library/1wzak8d0%28VS.80%29.aspx in MFC

DayofWeek if you hop to .Net http://msdn.microsoft.com/en-us/library/system.dayofweek.aspx

You'll need a lookup table with countries/what days they consider weekends..you'll probably have to construct this, but you can get a list of countries from: http://www.iso.org/iso/english_country_names_and_code_elements

That list is ISO 3166.

It's updated and should be your "one-stop-shop" for the listing. From there, you'll match "weekends" to the countries. http://en.wikipedia.org/wiki/Workweek might help in figuring out weekends/workweeks for countries.




回答2:


The following code will provide whether or not it is considered the weekend, with an option for different cultures (where the weekend starts/ends on a different day):

    /// <summary>
    /// Returns true if the specified date is weekend in given culture
    /// is in. 
    /// </summary>
    public static bool IsItWeekend(DateTime currentDay, CultureInfo cultureInfo)
    {
        bool isItWeekend = false;

        DayOfWeek firstDay = cultureInfo.DateTimeFormat.FirstDayOfWeek;

        DayOfWeek currentDayInProvidedDatetime = currentDay.DayOfWeek;

        DayOfWeek lastDayOfWeek = firstDay + 4;

        if (currentDayInProvidedDatetime == lastDayOfWeek + 1 || currentDayInProvidedDatetime == lastDayOfWeek + 2)
            isItWeekend = true;

        return isItWeekend;         
    }



回答3:


ICU project might help. It is designed for software internalization and globalization. C/C++ and Java version are available.

icu-project.org



来源:https://stackoverflow.com/questions/3102839/determine-regional-business-days-and-weekend-days-of-the-week

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!