Let the Delphi program be unaffected by the Windows date format (using the SetLocaleInfo function and application.updateformatsettings)

Source: Internet
Author: User

If the Windows system's short date format is "Yyyy/m/d", execute the following code to give an error: 2013-01-29 00:00:00 is not a valid date
Procedure Tfrmquerysale.formshow (Sender:tobject);
Var
sdate:string;
Begin
inherited;
The default check day sales data
Sdate: = FormatDateTime (' Yyyy-mm-dd ', now);
Datetimepicker1.datetime: = strtodatetime (sdate + ' 00:00:00 ');
Datetimepicker2.datetime: = strtodatetime (sdate + ' 23:59:59 ');
Find (Trim (Edtbillid.text), Datetimepicker1.datetime, datetimepicker2.datetime);
Edtbillid.setfocus;
End

How to solve?
Procedure Tdmcommonfun.setsysdateformat;
Begin
Format a short date for a Windows system
SetLocaleInfo (Locale_system_default, locale_sshortdate, ' yyyy-mm-dd ');

Application.updateformatsettings: = False;
Set the date time format used by the program itself
Longdateformat: = ' yyyy-mm-dd ';
Shortdateformat: = ' yyyy-mm-dd ';
Longtimeformat: = ' hh:nn:ss ';
Shorttimeformat: = ' hh:nn:ss ';
DateSeparator: = '-';
TimeSeparator: = ': ';
End
Executes the above code when the program is initialized, regardless of how the short date format of Windows is set no longer affects
Delphi program.

Xe2 above version, the code should be changed:

Procedure Setsysdateformat;
Var
Fs:tformatsettings;
Begin
Format a short date for a Windows system
SetLocaleInfo (Locale_system_default, locale_sshortdate, ' yyyy-mm-dd ');
Application.updateformatsettings: = False;
Set the date time format used by the program itself
Fs. Longdateformat: = ' yyyy-mm-dd ';
Fs. Shortdateformat: = ' yyyy-mm-dd ';
Fs. Longtimeformat: = ' hh:nn:ss ';
Fs. Shorttimeformat: = ' hh:nn:ss ';
Fs. DateSeparator: = '-';
Fs.timeseparator: = ': ';
End

Http://www.cnblogs.com/hnxxcxg/archive/2013/01/30/2882672.html

Let the Delphi program be unaffected by the Windows date format (using the SetLocaleInfo function and application.updateformatsettings)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.