Delphi如何以指定的格式将字符串转换为TDateTime?在英文XP sp3, 地区设为中国的情况下, StrToDateTime('2010-9-10 9:45:47')是没问题的.
但是一切换到俄文系统里, 就会提示 "2010-9-10 9:45:47" is not a valid date and time.看帖子说要改系统的区域设置; 但是部署起来我们不能这么搞客户的电脑. 所以还得从代码的角度来解决.另外在FormCreate时已经加上了:
DateSeparator := '-';
TimeSeparator := ':';
LongTimeFormat := 'yyyy-m-d hh:MM:ss';// 或'yyyy-mm-dd hh:MM:ss';还是不行. 望哪位有解决方案?
========================
第二个问题是:
在我电脑上, 用emeditor的binary(ASCII View)打开文本文件, ø 显示为外径的形象,
到俄文系统中用记事本打开就是ш了, delphi打开的也是相同的情况.哪位能解决这样的encoding问题啊?
但是一切换到俄文系统里, 就会提示 "2010-9-10 9:45:47" is not a valid date and time.看帖子说要改系统的区域设置; 但是部署起来我们不能这么搞客户的电脑. 所以还得从代码的角度来解决.另外在FormCreate时已经加上了:
DateSeparator := '-';
TimeSeparator := ':';
LongTimeFormat := 'yyyy-m-d hh:MM:ss';// 或'yyyy-mm-dd hh:MM:ss';还是不行. 望哪位有解决方案?
========================
第二个问题是:
在我电脑上, 用emeditor的binary(ASCII View)打开文本文件, ø 显示为外径的形象,
到俄文系统中用记事本打开就是ш了, delphi打开的也是相同的情况.哪位能解决这样的encoding问题啊?
DecodeDate();
EncodeTime();
DecodeTime();来相互转换。
你须得用 utf-8/unicode 来保存。
-----------------------------------------
var一个全局变量:
fmt: TFormatSettings;
FormCreate的时候:
GetLocaleFormatSettings(936, fmt);//LOCALE_USER_DEFAULT 936
fmt.DateSeparator := '-';
fmt.TimeSeparator := ':';
fmt.LongDateFormat := 'yyyy-m-d';
fmt.ShortDateFormat :='yyyy-m-d';
fmt.LongTimeFormat := 'h:M:s';
fmt.ShortTimeFormat := 'h:M:s'
用的时候:
datetime := StrToDateTime(datetimeString, fmt);\
就获得了TDateTime对象;
第二个问题:
---------------------------------
以指定编码打开文本文件, 以前google的关键词是encode, encoding,
实际上应该是codepage, 这样的话, 就很容易找到TStreamReader和
TStreamWriter, 它们带有参数可以以指定codepage打开及写入文件:
用法如下:
reader := TStreamReader.Create(TFileStream.Create(OpenDialog1.FileName,
fmOpenRead), TEncoding.ASCII);
while (not reader.EndOfStream) do
begin
line := reader.ReadLine;
...............
关键是其中的: "TEncoding.ASCII"