Support

Account

Home Forums General Issues Remove seconds from Time Picker

Solving

Remove seconds from Time Picker

  • Is it possible to remove the “seconds” from the time picker?

    • tabboy

    • December 12, 2017 at 5:59 pm

    Set the display format to “H:i” by selecting the custom radio button option. Only issue I found with this is that it saves the time to the database with seconds so I used this hook to remove the seconds when it saves it.

    add_filter( 'acf/update_value/type=time_picker', 'acf_update_date_time_picker_value', 10, 3 );
    
    function acf_update_date_time_picker_value( $value, $post_id, $field ) {
        return date('Y-m-d H:i',strtotime($value));
    }
  • Same issue. When trying the above fix, when I click on the field it still brings up a popup asking the user to enter hour, minute and seconds, rather than just asking for the hour and minute. Having it ask for seconds is confusing since when entering events, there will never be an event that has a start/end second other than :00 so just cluters the interface. Is there a way to disable this?

  • I’d love to see this added too, I’d imagine that setting the exact number of seconds isn’t necessary for most use cases and it makes the input a little confusing. An option to toggle this off in ACF would be ideal.

    It’s a bit of a hack, but I fixed this by adding some custom CSS to my admin page that simply sets a display:none on the seconds selector:

    function remove_acf_time_picker_seconds() { ?>
      <style>
        .ui_tpicker_second,
        .ui_tpicker_second::before {
          display: none !important;
        }
      </style>
    <?php }
    add_action('admin_head', 'remove_acf_time_picker_seconds');
  • The ACF timepicker bites. 🙂

    I’m writing an addon plugin to use this:

    http://jonthornton.github.io/jquery-timepicker/

  • It’s possible to add a JS filter to set the arguments for the jQuery Timepicker instantiation.

    Something like the following although I wasn’t able to actually get it working.

    
    (function($) {
      acf.add_filter('date_time_picker_args', function( args, $field ){
        args.units = ['hour', 'minute'];
        return args;		
      });
    })(jQuery);
    

    It’s documented here – https://www.advancedcustomfields.com/resources/adding-custom-javascript-fields/ – but this contradicts the ACF JS API docs which says to use .addFilterhttps://www.advancedcustomfields.com/resources/javascript-api/.

  • To hide the seconds input, use the following:

    
    (function() {
      acf.add_filter('date_time_picker_args', function( args, field ){
        args.showSecond = false;
        return args;
      });
    })();
    

    There are also options for ‘showHours’, ‘showMinutes’, ‘showMillisec’, ‘showMicrosec’ and ‘showTimezone’.

    See the options tab in the documentation

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.