Recent

Author Topic: TTimeEdit 24 hour format  (Read 5941 times)

Nevada Smith

  • New Member
  • *
  • Posts: 20
TTimeEdit 24 hour format
« on: March 25, 2017, 12:02:20 pm »
I am using TTimeEdit in the implementation of a  countdown timer. TTimeEdit shows time in the hh:mm:ss AM format. How can I change it to 24 hour format, without AM/PM? Please advise.
(LCL documentation and the internet does not seem to have anything in this regard. There are a few related to Delphi, but those options does not seem to work with LCL)

jwdietrich

  • Hero Member
  • *****
  • Posts: 1232
    • formatio reticularis
Re: TTimeEdit 24 hour format
« Reply #1 on: March 25, 2017, 12:17:40 pm »
It's weird. On my computer, it is always in 24 hour format, event if I change the settings of the computer to a 12 hour format. I can't find any published properties that allow programmatic setting of the format, too.
function GetRandomNumber: integer; // xkcd.com
begin
  GetRandomNumber := 4; // chosen by fair dice roll. Guaranteed to be random.
end;

http://www.formatio-reticularis.de

Lazarus 2.2.6 | FPC 3.2.2 | PPC, Intel, ARM | macOS, Windows, Linux

Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
Re: TTimeEdit 24 hour format
« Reply #2 on: March 25, 2017, 12:29:00 pm »
The timedit takes its format from formatsettings.
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

jwdietrich

  • Hero Member
  • *****
  • Posts: 1232
    • formatio reticularis
Re: TTimeEdit 24 hour format
« Reply #3 on: March 25, 2017, 03:11:32 pm »
The timedit takes its format from formatsettings.

OK, but shouldn't the formatsettings be automatically updated on program launch?
function GetRandomNumber: integer; // xkcd.com
begin
  GetRandomNumber := 4; // chosen by fair dice roll. Guaranteed to be random.
end;

http://www.formatio-reticularis.de

Lazarus 2.2.6 | FPC 3.2.2 | PPC, Intel, ARM | macOS, Windows, Linux

Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
Re: TTimeEdit 24 hour format
« Reply #4 on: March 25, 2017, 03:13:52 pm »
Yes, but you can clone formatsettings for your app and adapt it.
But probably TTimedit needs a formatsettings field/property
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

Bart

  • Hero Member
  • *****
  • Posts: 5290
    • Bart en Mariska's Webstek
Re: TTimeEdit 24 hour format
« Reply #5 on: March 25, 2017, 11:17:40 pm »
Given the way you can select time, I would have thought that text would always be in hh:nn format.

Anyhow having a property of type TFormatSettings is a bit overkil.
It could have a TimeFormat property though.

Bart

Bart

  • Hero Member
  • *****
  • Posts: 5290
    • Bart en Mariska's Webstek
Re: TTimeEdit 24 hour format
« Reply #6 on: March 25, 2017, 11:36:46 pm »
OK, but shouldn't the formatsettings be automatically updated on program launch?

On Windows it does AFAIK, on *nix you need to include the clocale unit somewhere (I think).

Bart

Nevada Smith

  • New Member
  • *
  • Posts: 20
Re: TTimeEdit 24 hour format
« Reply #7 on: March 26, 2017, 12:56:31 pm »
Thank you folks. I eventually moved on, and ended up using TDateTimePicker.

Thonolan

  • Newbie
  • Posts: 4
Re: TTimeEdit 24 hour format
« Reply #8 on: February 22, 2024, 02:59:40 pm »
I have found the settings to force the time settings.

In sysutils unit. It sets a record on startup. with the Default formats from the Windows Regional settings.
These can be over written by your own program.

in your form1.create put the following two lines.

 Sysutils.DefaultFormatSettings.LongTimeFormat:='hh:mm:ss';
 Sysutils.DefaultFormatSettings.ShortTimeFormat:='hh:mm';

This will force TTimeEdit to use 24 hour settings.

If your windows settings are already on 24 hour mode You will see no difference.

The DefaultFormatSettings is reloaded from Windows on each run.
« Last Edit: February 22, 2024, 03:03:06 pm by Thonolan »

Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
Re: TTimeEdit 24 hour format
« Reply #9 on: February 22, 2024, 04:35:23 pm »
Is the wrong approach.
https://forum.lazarus.freepascal.org/index.php/topic,36311.msg241852.html#msg241852
Do what I told you.
Do NOT modify the global settings. That goes for the other ill-informed answers as well: shame on you!
« Last Edit: February 22, 2024, 04:42:31 pm by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: TTimeEdit 24 hour format
« Reply #10 on: February 25, 2024, 07:13:50 pm »
Just committed to Laz/main a change to TTimeEdit which introduces new TimeFormat and TimeSeparator properties. Now the formatting of the time edit control can be freely adjusted.

TimeFormat, by default, is an empty string which means that the ShortTimeFormat value of the current DefaultFormatSettings is used. All format strings accepted by FormatDateTime can be entered except for those which contain a date part (d, y, m at the wrong place) (because the control is meant for time input only).

TimeSeparator, by default, is also an empty string meaning that the TimeSeparator of the DefaultFormatSettings will be used. Only the first character of the value is used.

The attached project demonstrates this new feature. Note that Laz/main is absolutely required to use the project.
« Last Edit: February 25, 2024, 07:37:04 pm by wp »

jamie

  • Hero Member
  • *****
  • Posts: 6130
Re: TTimeEdit 24 hour format
« Reply #11 on: February 25, 2024, 08:32:59 pm »
Nice fix, is it possible to place an example hint note in the OI at the bottom for the time format property?


"Optional Text" hh:nn:ss:zz ?

The only true wisdom is knowing you know nothing

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: TTimeEdit 24 hour format
« Reply #12 on: February 25, 2024, 10:09:55 pm »
Wait a bit. I guess dsiders will soon pick this up and write a help text - this is what appears at the bottom of the object inspector. But it will have to be more general than the specific example that I used in the demo.

dsiders

  • Hero Member
  • *****
  • Posts: 1080
Re: TTimeEdit 24 hour format
« Reply #13 on: February 26, 2024, 01:23:31 am »
Nice fix, is it possible to place an example hint note in the OI at the bottom for the time format property?


"Optional Text" hh:nn:ss:zz ?

Not until there's documentation written for it.

Edit
Werner beat me to it...
Preview Lazarus 3.99 documentation at: https://dsiders.gitlab.io/lazdocsnext

 

TinyPortal © 2005-2018