Top.Mail.Ru
Мастера DELPHI, Delphi programming community Титульная страница Поиск, карта сайта Написать письмо 
| Новости | Поиск | FAQ | Статьи | Книги | Новости VCL |
| Форумы ЧАТ | Орешник | KOL и MCK |
Форумы -» Основная («Начинающим»)/ Базы / WinAPI / Компоненты / Сети / Media / Игры / Corba и COM / KOL / FreePascal / .Net / Прочее / RSDN.ORG

« предыдущая ветвь | форум | следующая ветвь »

Установить в программе формат вывода даты для DateTimePicker


lightix ©   (2004-07-27 10:15:00) 

Компонент DateTimePicker похоже берет формат вывода даты\времени из системных настроек, а можно ли не меняя этих настроек в системе, локально в программе изменить формат отображения даты (времени) ?
В частности пробовал сделать 2-значный год с помощью ShortDateFormat = "dd.mm.yy"; - на DateToStr действует, на DateTimePicker - нет.


lightix   (2004-07-27 12:55:00) [1]

y-soft ©   (27.07.04 11:36) [19]
Спасибо тебе огромное, очень выручил!!!
Все работает замечательно!
Еще раз спасибо!


y-soft   (2004-07-27 11:36:00) [2]


unit Commctrl;

...
function DateTime_SetFormat(hwndDT : THandle; //YourDateTimePicker.Handle
lpzsFormat : PChar) : BOOL; //Format string
...


Из MSDN (раздел Date and Time Pickers Controls)
Format Strings
A DTP format string consists of a series of elements that represent a particular piece of information and define its display format. The elements will be displayed in the order they appear in the format string.

Date and time format elements will be replaced by the actual date and time. They are defined by the following groups of characters:

Element Description  
"d"  The one- or two-digit day.
"dd"  The two-digit day. Single-digit day values are preceded by a zero.
"ddd"  The three-character weekday abbreviation.
"dddd"  The full weekday name.
"h"  The one- or two-digit hour in 12-hour format.
"hh"  The two-digit hour in 12-hour format. Single-digit values are preceded by a zero.
"H"  The one- or two-digit hour in 24-hour format.
"HH"  The two-digit hour in 24-hour format. Single-digit values are preceded by a zero.
"m"  The one- or two-digit minute.
"mm"  The two-digit minute. Single-digit values are preceded by a zero.
"M"  The one- or two-digit month number.
"MM"  The two-digit month number. Single-digit values are preceded by a zero.
"MMM"  The three-character month abbreviation.
"MMMM"  The full month name.
"t"  The one-letter AM/PM abbreviation (that is, AM is displayed as "A").
"tt"  The two-letter AM/PM abbreviation (that is, AM is displayed as "AM").
"yy"  The last two digits of the year (that is, 1996 would be displayed as "96").
"yyyy"  The full year (that is, 1996 would be displayed as "1996").

To make the information more readable, you can add body text to the format string by enclosing it in single quotes. Spaces and punctuation marks do not need to be quoted.

Note Nonformat characters that are not delimited by single quotes will result in unpredictable display by the DTP control.

For example, to display the current date with the format "'Today is: 04:22:31 Tuesday Mar 23, 1996", the format string is "'Today is: 'hh':'m':'s dddd MMM dd', 'yyyy". To include a single quote in your body text, use two consecutive single quotes. For example, "'Don''t forget' MMM dd',' yyyy" produces output that looks like: Don't forget Mar 23, 1996. It is not necessary to use quotes with the comma, so "'Don''t forget' MMM dd, yyyy" is also valid, and produces the same output.


Прекрасно работает


lightix   (2004-07-27 10:53:00) [3]

ZrenBy ©   (27.07.04 10:48) [16]
Весь и вопрос в том как не меняя системные настройки сделать нужный формат вывода


Sandman25   (2004-07-27 10:51:00) [4]

[16] ZrenBy ©   (27.07.04 10:48)

Имелось ввиду, что при изменении shortdateformat программно, не изменяется вид контрола, а используется тот shortdateformat, который был при старте программы.


ZrenBy   (2004-07-27 10:48:00) [5]

DateTimePicker - это аллес цурюк

Системные настройки = 'dd.mm.yy'

Дата в DateTimePicker при просмотре отображается в нужном формате.

Но в режиме редактирования год отображается все равно четырьмя знаками.

Проверено - D6, VS.NET 2003 С++, С#


lightix   (2004-07-27 10:46:00) [6]

Sandman25 ©   (27.07.04 10:40) [13]
А я в виде дат и передаю. Это я просто для примера сказал что DateToStr срабатывает а пикер нет.

Anatoly Podgoretsky ©   (27.07.04 10:41) [14]
Win2k Terminal Server. Пользователь подсоединяется терминалом и там уже запускаются все програмы.
Удобно, даже с 486-х работает, и не надо париться пользователям на компы переинсталивать программы (предприятие баааальшущее у нас).


Anatoly Podgoretsky   (2004-07-27 10:41:00) [7]

lightix   (27.07.04 10:39) [11]
Что делает пользователь на сервере приложений?


Sandman25   (2004-07-27 10:40:00) [8]

[11] lightix   (27.07.04 10:39)

Чтобы не было таких проблем, даты нужно передавать в виде TDate, а не String


lightix   (2004-07-27 10:40:00) [9]

Sandman25 ©   (27.07.04 10:39) [10]
Понятно, а я в BCB5 пишу ...


lightix   (2004-07-27 10:39:00) [10]

Да нельзя мне на сервере приложений менять формат даты ...это ж затронет все программы


Sandman25   (2004-07-27 10:39:00) [11]

[9] lightix   (27.07.04 10:38)

В D6 есть.


lightix   (2004-07-27 10:38:00) [12]

2 Sandman25 © (27.07.04 10:37) [7]
Нет там такого свойства


Sandman25   (2004-07-27 10:38:00) [13]

Но вообще-то прав [6] Anatoly Podgoretsky ©   (27.07.04 10:36)


Sandman25   (2004-07-27 10:37:00) [14]

DateTimePicker1.Format := 'dd.mm.yy'


Anatoly Podgoretsky   (2004-07-27 10:36:00) [15]

lightix   (27.07.04 10:21) [3]
Скажено же, ты второй в очереди после пользователя.


lightix   (2004-07-27 10:35:00) [16]

в том то и дело что нужен именно DateTimePicker. Если не получится тогда поставлю ComboBox + по клику MonthCalendar. Но не хочется, ибо дописывать еще проверки всякие ...


Ega23   (2004-07-27 10:33:00) [17]

lightix   (27.07.04 10:21) [3]

Выведи в MaskEdit


lightix   (2004-07-27 10:21:00) [18]

А как его вид можно по-другому определить? Мне нужно формат даты DD.MM.YY


Ega23   (2004-07-27 10:20:00) [19]

Как для DateTimePicker - не знаю, а у TDateEdit из RxLib есть свойство.


Anatoly Podgoretsky   (2004-07-27 10:16:00) [20]

Сугубо системный компонент и вид определяется пользователем на приоритетной основе.


Наверх

Титульная страница Поиск, карта сайта Написать письмо