Dynamic Setting System Date Format 1 Problem When you operate the database table, you usually need to process the data of the date type in the table. There are a variety of date formats in the system. There are also multiple formats in the date field of the database. When the date field in the database table must match the date format to insert the data, in this case, the date format of the system is generally required to change the format that is consistent with the date field in the database table (because the design is designed) Already set, the format of the date is already unique, so in general, the date format of the system is changed), then it must be able to automatically change the date format of the system in the program to match the date format of the table! 2 Description of the system API for modifying the date format in the program mainly requires the following Windows Apibool setLocaleInfo (LCID Locale, // local identifier lctypel lctype, // type of information to set lpctstr lplcdata // pointer to information to set); this function Mainly used in the Windows system area option, mainly including the settings of time, language and other options. LCID: Locale Identifier has two defaults in the system: locale_system_default: system default zone option; local_user_default: current user's area option; while users can create LCIDs via the MAKELCID macro; LCTYPE: need to be set the system information type; includes the following values: LOCALE_ICALENDARTYPE LOCALE_SDATE LOCALE_ICURRDIGITS LOCALE_SDECIMAL LOCALE_ICURRENCY LOCALE_SGROUPING LOCALE_IDIGITS LOCALE_SLIST LOCALE_IFIRSTDAYOFWEEK LOCALE_SLONGDATE LOCALE_IFIRSTWEEKOFYEAR LOCALE_SMONDECIMALSEP LOCALE_ILZERO LOCALE_SMONGROUPING LOCALE_IMEASURE LOCALE_SMONTHOUSANDSEP LOCALE_INEGCURR LOCALE_SNEGATIVESIGN LOCALE_INEGNUMBER LOCALE_SPOSITIVESIGN LOCALE_ITIME LOCALE_SSHORTDATE LOCALE_S1159 LOCALE_STHOUSAND LOCALE_S2359 LOCALE_STIME LOCALE_SCURRENCY LOCALE_STIMEFORMAT lpLCData: need to store address information set;
With the corresponding function for INT GETLOCALEINFO (
LCID LOCALE, // local identifier lctype lctype, // type of information lptstr lplcdata, // address LPTSTR LPLCDATA, / / Address Of Buffer for Information INT CCHDATA / / SIZE OF BUFFER; mainly used to obtain regional settings of the current system, each parameter and use process Also explained again. Application Example 3 // Get current system date format short; function Tfrmmain.GetsysDateFormat: string; var sgs: string; begin setlength (sgs, 12); GetLocaleInfo (LOCALE_SYSTEM_DEFAULT, LOCALE_SSHORTDATE, PChar (sgs), 12); result: = String (PCHAR (SGS)); END;
// Set the system date format; procedure tfrmmain.setsysdateformat (s: string); begin setLocaleInfo (locale_system_default, local_sshortdate, pchar (s));