kartik-v / yii2-widget-timepicker

Enhanced Yii2 wrapper for the bootstrap timepicker plugin (sub repo split from yii2-widgets).
Other
41 stars 12 forks source link

show Meridian not convert 24 hours format correctly #5

Closed rumes closed 5 years ago

rumes commented 8 years ago

I have used kartik timepicker widget in my project as below.

     <?= $form->field($model, 'end_time')->widget(TimePicker::classname(), [
            'pluginOptions' =>
            [
                'defaultTime' => $time_now,
                'showMeridian' => true,
            ],

            ]);
        ?> 

but if pass time like 14:15 to the widget it shows time as 12:15 AM

noc2spam commented 8 years ago

Confirmed. For me it always shows 12:00AM ( for example, my time is 14:00). Only happens with PM times. Widget setup:

<?php

echo TimePicker::widget([
    'name' => "DoctorSchedulePreferences[$scheduleId][end_time]",
    'value' => (isset($schedule[$key]) ?
            $schedule[$key]->end_time : ''),
    'pluginOptions' => [
        'defaultTime' => false,
        'showMeridian' => true,
    ],
    'options' => ['class' => "txtSchedule_end_time_$key"],
]);
?>

Screenshot: Screenshot

bhattaxay commented 7 years ago

Yes, I am facing same issue when I am going to update time it passes 12:00 AM. Have you found any solution?

bhattaxay commented 7 years ago
Hello,

I got the solution for it. It insert the same value because you have not passes the time format properly.

Try this below code in your create or update function of controller:
$model->eventStartDate = date('Y-m-d',strtotime($_REQUEST['eventStartDate']));

$model->eventStartTime = date('H:i:s',strtotime($_REQUEST['eventStartTime']));
stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

jorgemorahenao commented 4 years ago

Hi, we were working with Postgres DB, and had a simiar issue, when we were creating the event, and the hour was set with PM, the time was successfully saved to the DB, but, when we updated the event, the time was wrong in the TimePicker input, so, to solve this, it's needed to do something similar like @bhattaxay said on https://github.com/kartik-v/yii2-widget-timepicker/issues/5#issuecomment-271077665 We solved the problem formatting the time this way:

$model->start_time = date('g:i a', strtotime($model->start_time));

The input is configured like this:

<?= $form->field($model, 'start_time')->widget(TimePicker::classname(), []) ?>