emersonthis
emersonthis

Reputation: 33348

cakePHP: How to format time duration as MM:SS

I have an input in my form that needs to specify a length of time in minutes and seconds (not a specific date/time). How do I do this?

    echo $this->Form->input('time', array('type'=>'time', 'timeFormat'=>24));
    //results in HH:MM but I need MM:SS

Upvotes: 1

Views: 749

Answers (2)

MaNKuR
MaNKuR

Reputation: 2694

I will rather prefer you to go for JS timepicker. Just add a the plugin to your porject and use its feature as per requirement listed in below link http://www.jquery4u.com/plugins/10-jquery-time-picker-plugins/

hope this will help!!

Upvotes: 0

thaJeztah
thaJeztah

Reputation: 28987

The default FormHelper does not support this, so you will have to use a regular 'text' input ('type' => 'text') and parse/format the value in the beforeValidate() of your Model.

Alternatively, you can create two dropdowns (minutes and second), OR use a dateTime input and hide the non-relevant dropdowns with CSS, but this may a bit 'dirty'

You will also need to create a custom validation-rule to validate your value; see Adding your own Validation Methods, because the built-in 'time' validation rule does not validate seconds.

Upvotes: 1

Related Questions