i realize that ShortDateFormat
variable represents the user's preferences.
i also realize that if settings change, Delphi will automatically refresh the ShortDateFormat
variable with the user's settings.
mm/dd/yy
i have a customer who wants all "short dates" to be displayed in a particular, but they don't want to their Windows preferences.
mm/dd/yyyy
What is a good way to globally, in my application, change the ShortDateFormat
variable, given that it can be reset at any time?
Note: example date format masks in code format included to make the post more visually appealing
Have your own FormatSettings and use it explictly with all the format routines instead of using the implicit version.
It has also the advantage of being Thread safe.
function DateTimeToStr(const DateTime: TDateTime): string;
function DateTimeToStr(const DateTime: TDateTime; const FormatSettings: TFormatSettings): string;
Update: to avoid your application to react to locale changes, you can change Application.UpdateFormatSettings
to False
.
It is defaulted to True
in TApplication.Create
.
But beware this is not 100% bulletproof for all settings as some routines go get the ThreadLocale directly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With