简体   繁体   中英

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

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 US 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:

// David's Suggestion:
dtLastOnline := dedtLastOnline.Date + tpLastOnline.Time;

Thanks

  • Jeff

You need to store dates and times in a standard format (eg 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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM