开发者

Date / Time differs on U.S and E.U PC's - Delphi doesn't like that

开发者 https://www.devze.com 2023-02-11 00:46 出处:网络
I am using DateTime values in my program. Everything works fine on my danish Windows 7, when using them - however, when I send my app to someone with a U.S based PC (with the different Date/Time forma

I am using DateTime values in my program. Everything works fine on my danish Windows 7, when using them - however, when I send my app to someone with a U.S based PC (with the different Date/Time format), it blows up. I get those xx-xx-xx is not a valid date and time value" (or something like that).

I tried setting the LongDateFormat and the DateSeparator values at the startup of my program, however that doesen't work either?

What do I have to do, so that my app will have the same date/time format, no matter where its being run from?

EDIT: Here's what I do to create the DateTime value:

// Davi开发者_如何学编程d's Suggestion:
dtLastOnline := dedtLastOnline.Date + tpLastOnline.Time;

Thanks

  • Jeff


You need to store dates and times in a standard format (e.g. a Delphi TDateTime). You only convert them to human readable forms when you display them.

After your edit to clarify, what you need to do is to convert the date and time separately and then add together the two resulting TDateTime values.

So your code should be:

dedtLastOnline.Date + tpLastOnline.Time


Where do you get that "is not a valid date and time value" error? Seems a "string to TDatetime" conversion error, which has nothing to do with a ".Date + .Time" calculation. Do you have a stack trace?

0

精彩评论

暂无评论...
验证码 换一张
取 消