zoukankan      html  css  js  c++  java
  • MFC获取系统信息

    一、获取系统时间

                CString str,str2;
                CTime time;
                time = CTime::GetCurrentTime();
                str = time.Format("%Y年%m月%d日 %X");
                str2 = time.Format(_T("%Y-%m-%d   %H:%M:%S"));

                 格式符号说明
                %a —— 星期(缩写英文),如Fri;
                %A —— 星期(全写英文),如Friday
                %b —— 月份(缩写英文),如Oct
                %B —— 月份(全写英文),如 October
                %c  —— 月 / 日 / 年 时 : 分:秒,如 10 / 13 / 06 19 : 17 : 17
                % d  —— 日期(1 ~31)
                %H  —— 时(24小时制)(0 ~23)
                %I    —— 时(12小时制)(0 ~12)
                %j    —— 一年当中的第几天,(1 ~366)
                %m  —— 月份(数字 1 ~12)
                %M  —— 分(0 ~59)
                %p  —— 12小时中的A M / PM指示,或者AM,或者PM
                %S  —— 秒(0 ~59)
                %U  —— 一年中的第几周,星期日作为每周的第一天(0 ~53)
                %w  —— 星期(数字表示,0 ~6,0代表星期日)
                %W —— 一年中的第几周,星期一作为每周的第一天(0 ~53)
                %x   —— 月 / 日 / 年,%c的前半段

               %X   —— 时:分 : 秒,%c的后半段

                SYSTEMTIME localtime,systime;
                CString strDate, strTime;
                GetLocalTime(&localtime);//获取本地时间。
                GetSystemTime(&systime);//这个时间采用的是“协同世界时间”(即UTC,也叫做GMT)格式

                GetSystemTime:所返回的是UTC.
                协调世界时(Coordinated Universal Time,简写作UTC,之前也被拼做Universal Time Coordinated,
                有时是Universal Coordinated Time)是由国际无线电咨询委员会定义和建议采用的,
                并由国际时间局(BIH)负责保持的以国际单位制(SI)秒为单位的时间标度。
                对与无线电规则相关的大部分实际应用而言,协调世界时(UTC)与本初子午线(经度零度)
                上的平均太阳时等效。该时间过去以格林威治平均时(GMT)表示。  
                协调世界时使用24小时制的时钟表示,但也可以被转换为12小时制的时钟(AM和PM)。
                UTC用于飞行和航海,它有时也被称作祖鲁。UTC使用阳历

    二、获取系统言语和地域

                //获取系统默认言语,不随用户改变言语设置而改变(ICID与言语对照表)
                LCID lcid=GetSystemDefaultLCID();
                LANGID langid=GetUserDefaultUILanguage();
                LANGID langid1=GetSystemDefaultUILanguage();
                if (lcid == 0x804)
                {
                  //指中华人民共和国   
                }
                WORD PriLan = PRIMARYLANGID(lcid);   //主语言(中文)
                WORD SubLan = SUBLANGID(lcid);       //子语言(中文简体或中文繁体)
                //获取用户当前系统言语(形式)
                const int BUFFER_SIZE = 10;
                TCHAR szLanguage[BUFFER_SIZE] = { 0 };
                TCHAR szCountry[BUFFER_SIZE] = { 0 };
                DWORD dwCount = sizeof(TCHAR)*BUFFER_SIZE;
                int ccLanguage = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SISO639LANGNAME, szLanguage, dwCount);
                int ccCountry= GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SISO3166CTRYNAME, szCountry, dwCount);
                //系统默认、不随用户改变言语设置而改变
                GetLocaleInfo(LOCALE_SYSTEM_DEFAULT, LOCALE_SISO639LANGNAME, szLanguage, dwCount);
                GetLocaleInfo(LOCALE_SYSTEM_DEFAULT, LOCALE_SISO3166CTRYNAME, szCountry, dwCount);
                //获取用户系统地域信息(位置)
                GEOID geoId;
                int sizeOfBuffer;
                TCHAR szName[BUFFER_SIZE] = { 0 };
                geoId = GetUserGeoID(GEOCLASS_NATION);
                sizeOfBuffer = GetGeoInfoW(geoId, GEO_ISO2, NULL, 0, 0);
                GetGeoInfoW(geoId, GEO_ISO2, szName, sizeOfBuffer, 0);

    三、补充

    参考:https://docs.microsoft.com/zh-cn/windows/desktop/api/winnls/nf-winnls-getlocaleinfoa

    int GetLocaleInfo(
    LCID Locale, // locale identifier
    LCTYPE LCType, // information type
    LPTSTR lpLCData, // information buffer
    int cchData // size of buffer
    );
    参数解释:
    Locale --------- Long
            欲为其获得信息的地方ID。系统预设有如下几个:
    LCType --------- Long
            要取回的信息类型。参考api32.txt文件中带 LOCALE_前缀的常数。
            用OR运算符合并LOCALE_NOUSEROVERRIDE,从而强制使用系统默认信息——即使当前用户已修改了相关设置
    lpLCData ------- String
            指定一个缓冲区,用于装载要求的信息。注意预先将字串格式化成合适的长度
    cchData -------- Long
            lpLCData缓冲区的长度;如设为零,表示获取必要的缓冲区长度
    返回值:
    Long,装载到缓冲区的字符数,或者cchData要求的缓冲区长度。
    参考:https://docs.microsoft.com/zh-cn/windows/desktop/api/winnls/nf-winnls-getgeoinfoa
    int GetGeoInfoA(
      GEOID   Location,
      GEOTYPE GeoType,
      LPSTR   lpGeoData,
      int     cchData,
      LANGID  LangId
    );

    参数解释:

    Location:表示想要获取信息的地理位置。
    Identifier for the geographical location for which to get information.
    For more information, see Table of Geographical Locations.
    You can obtain the available values by calling EnumSystemGeoID.
    GeoType: 
    Type of information to retrieve. Possible values are defined by the SYSGEOTYPE enumeration.
    If the value of GeoType is GEO_LCID, the function retrieves a locale identifier.
    If the value of GeoType is GEO_RFC1766, the function retrieves a string name that is
    compliant with RFC 4646 (Windows Vista). For more information, see the Remarks section.
    lpGeoData
    Pointer to the buffer in which this function retrieves the information.
    cchData
    Size of the buffer indicated by lpGeoData. The size is the number of bytes
    for the ANSI version of the function, or the number of words for the Unicode version.
    The application can set this parameter to 0 if the function is to return the required
    size of the buffer.
    LangId
    Identifier for the language, used with the value of Location. The application can
    set this parameter to 0, with GEO_RFC1766 or GEO_LCID specified for GeoType.
    This setting causes the function to retrieve the language identifier by calling GetUserDefaultLangID.
     
     
  • 相关阅读:
    php字符串处理函数大全 转
    php http Manual
    HTTP协议详解 百度文库
    PHP获取指定日期的上个月的日期 转
    计算指定日期的前N个月日期
    MySQL之count(*)与count(id)效率比较<转>
    生成器
    可迭代对象_迭代器
    变量内容的删除替换和替代
    软件磁盘阵列
  • 原文地址:https://www.cnblogs.com/cteng-common/p/getlocaleinfo.html
Copyright © 2011-2022 走看看