0

I am using Ionic Timepicker. When I select a time it's passing values like 75600 (here I have selected 09:00pm). How to actually retrieve a human readable string instead of an "epoch time" value?

Here's my code:

    $scope.timePickerObject12Hour.inputEpochTime = val;
    console.log(val);
    // here i am getting 79200
    var selectedTime = new Date();
    var amPmHour = $filter('date')(selectedTime, 'hh');
    console.log(amPmHour);
    // here i am getting 07
    console.log('Selected epoch is : ', val, 'and the time is ', selectedTime.getUTCHours(), ':', selectedTime.getUTCMinutes(), 'in UTC');
    //here i am getting Selected epoch is :  75600 and the time is  16 : 5 in UTC

1 Answer 1

1

Simply using the plain Javascript Date object:

new Date($scope.timePickerObject12Hour.inputEpochTime*1000);

Don't forget to multiply the "epoch time" value you get from Ionic Timepicker by 1000, since the Javascript Date constructor takes a number of milliseconds, not seconds.

in your case, the following code:

console.log($filter('date')(new Date(79200*1000), 'hh:mma'));

... would output:

09:00PM

Here's a working JSFiddle (link) that will feature a working example using the tools you're working with.

Sign up to request clarification or add additional context in comments.

4 Comments

controller i am getting value like that
i have follwed this github.com/rajeshwarpatlolla/ionic-timepicker pls check and say ur answer
if i select 10.00pm console i am getting 3.30pm it not working correct
check your jsfiddle code it's showing 3.30 instead of 9.00pm

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.