By Gae58 on
Hi, reading the features of the datetime element I noticed that you can turn off the date part and/or the time part.
I have 2 difficulties regarding the indexes
'#date_time_format' => 'H',
'#default_value' => '11:00',
#date_time_format whether I put H or whether I put H:i it always displays me the time with hour:minutes:seconds
#default_value I can't assign a value to it
Comments
Excuse me I attach the code
Excuse me I attach the code$form['time_container']['time'] = [
'#type' => 'datetime',
'#title' => $this->t('Time'),
'#date_date_element' => 'none',
'#date_time_element' => 'time',
'#date_time_format' => 'H',
//'#default_value' => '11:00',
'#default_value' => time(),
];
See the following document
See the following document "public static function Datetime::processDatetime".
To get rid from seconds you can use the #date_increment property.
To set current time as default value you can use the following code:
But if you need to set a specific time, pass a string as the second parameter, like this:
The example
Hi wombatbuddy, thanks for
Hi wombatbuddy, thanks for the link and the sample code.
It all works