2

I recommend using the Time Field module which provides a time field for you. TimeField for Drupal 8 solves displaying and submitting time and time-range for Drupal site.


1

Twig's date extension does exactly what you ask: {{ created | time_diff }} However, this extension isn't in Drupal by default, assuming you're using Composer you need to add this extension to your project by running: composer require twig/extensions


1

You'll need a external library to do that. Something like jQuery UI Month Picker Plugin and you'll probably will need to use a textfield rather than date. OR Use the Month Year module This module provides a month year field type.


1

If you want to alter the way this component is shown globally, you can implement hook_preprocess_datetime_form(), eg. like this: function mymodule_preprocess_datetime_form(&$variables) { // Ensure there's a month field and it's a select. if (isset($variables["content"]["month"]) && $variables["content"]["month"]['#type'] === 'select') { ...


1

There is no DateTime class in Drupal\Core\Datetime you should use DrupalDateTime class instead try with. use Drupal\Core\Datetime\DrupalDateTime; //$userTimezone = new DateTimeZone(drupal_get_user_timezone()); $gmtTimezone = new DateTimeZone('GMT'); $myDateTime = new DrupalDateTime($item['start_date'], $gmtTimezone); $dateTime = $...


1

This code is working for me. // set use timezone userTimezone = new DateTimeZone(drupal_get_user_timezone()); // set gmt timezone $gmtTimezone = new DateTimeZone('GMT'); // Take the timestamp. $start_date = $val['field_start_time_value']; $startDateTime = new DateTime($start_date, $gmtTimezone); $offset = $userTimezone->getOffset($startDateTime); $...


Only top voted, non community-wiki answers of a minimum length are eligible