How to convert string time to Ionic time for PHP with MySQL?

0

Good morning, I'm passing the server a string that would be for time: 23:45 is an example.

In my $ _GET I'm trying to convert this way:

$prazo_entrega_min = time("hh:mm", strtotime($_GET['prazo_entrega_min']));

But to no avail. What can I do?

I'm using the ionicTimePicker plugin ( link in my controller to get this date):

// TEMPO ENTREGA MINIMO
        var ipObj1 = {
            callback: function (val) { //Mandatory
                if (typeof (val) === 'undefined') {
                    console.log('Time not selected');
                } else {
                    var selectedTime = new Date(val * 1000);
                    console.log(selectedTime.getUTCHours(), 'H :', selectedTime.getUTCMinutes(), 'M');

                    $scope.entrega_min = selectedTime.getUTCHours() + ':' + selectedTime.getUTCMinutes();

                    window.localStorage.setItem("prazo_min_entrega", $scope.entrega_min)

                    console.log($scope.entrega_min);
                }
            },
            inputTime: 50400, //Optional
            format: 24, //Optional
            step: 15, //Optional
            setLabel: 'OK' //Optional
        };

        $scope.openTimePicker = function () {
            ionicTimePicker.openTimePicker(ipObj1);
        };

I am storing in my localstorage the values just to check, they are all in string:

What do I do wrong?

    
asked by anonymous 01.03.2017 / 15:26

1 answer

1

You are using the wrong function:

$prazo_entrega_min = time("hh:mm", strtotime($_GET['prazo_entrega_min']));

time() does not accept arguments, always brings UTC local time. The syntax you used looks more like date() (which would actually be H:i for hour: minutes), but would return a formatted date.

If your $ _GET value is string 23:45 and you need to turn it into a timestamp, use

$prazo_entrega_min = strtotime( $_GET['prazo_entrega_min'] );

strtotime() alone does what you need.

    
02.03.2017 / 03:44