PDA

View Full Version : DateTime Formatting



Voltrox
13-09-2006, 08:26 PM
Hi,

I'm trying to extract the different parts of the time from a string.

But i'm having a problem, I need to be able to set the formatting to 09:00 instead of 9:00 so that I can process it more accuratley.

Could someone show me how to format it?

Please...

Thank you.

AthenaOfDelphi
13-09-2006, 08:42 PM
Daft question time...

Are you reading the date/time from user input or from the system clock?

If its the later there are procedures that extract the component parts for you (decodeTime and decodeDate). If its the former and its a gui, why not use the date/time selectors?

As I said... probably a daft question... depends on what you want to achieve.

Voltrox
13-09-2006, 11:27 PM
sorry I was so daft :(

I was pulling it from the system time.

AthenaOfDelphi
14-09-2006, 05:53 PM
sorry I was so daft :(

I was pulling it from the system time.

You misunderstand me hon.... I wasn't calling you daft. I was putting a rider on my question in case it was silly. Its difficult to know how experienced people are and some people can be offended if you ask them simple questions.

If you are using 'now' to get the time, decodeDate and decodeTime should be perfect for your needs.

seiferalmasy
14-09-2006, 07:21 PM
You can also set the time format using sysutils.


SysUtils.ShortTimeFormat:='hh:mm:ss';
SysUtils.longTimeFormat:='hh:mm:ss';

You can put that anywhere in your code, like on form create. The above will force windows to use 24 hr clock, 2 digits for each part.

I am sure you can rearrange that so it gives desired output in the first place and then extract?

Sysutils works with date and time, as well as the joining character. You can set that to something like "-" or "." for example.


sysutils.TimeSeparator:=':';

and for dates :


SysUtils.shortDateFormat:='dd/mm/yyyy';
SysUtils.LongDateFormat:='dd/mm/yyyy';

etc

Voltrox
15-09-2006, 11:17 PM
Thank you. :)

That was very helpful seiferalmasy.

Thank you Athena.

:)