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

Gae58’s picture

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(),
 ];

wombatbuddy’s picture

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: 

'#default_value' => DrupalDateTime::createFromFormat('H:i', date('H:i'))

But if you need to set a specific time, pass a string as the second parameter, like this: 

'#default_value' => DrupalDateTime::createFromFormat('H:i', '11:00')

The example 

use \Drupal\Core\Datetime\DrupalDateTime;

$form['time_container']['time'] = [
  '#type' => 'datetime',
  '#title' => t('Time'),
  '#date_date_element' => 'none',
  '#date_time_element' => 'time',
  '#date_increment' => '60',
  // Set current time without seconds as default value.
  '#default_value' => DrupalDateTime::createFromFormat('H:i', date('H:i')),
  // Set 11:00 as default value.
  //'#default_value' => DrupalDateTime::createFromFormat('H:i', '11:00'),
];
Gae58’s picture

Hi wombatbuddy, thanks for the link and the sample code.
It all works