4

I'm trying to display the value of a field of type Time in a LWC.

The point is that from the Apex class I'm receiving an integer number instead of the standard time format string.

Here an example:
I expect to receive something like "18.15" but I'm retrieving this value "65700000".

1 Answer 1

3

Yes, you are right. The number you are getting is in milliseconds "65700000". We need to convert it to time format in js itself. I used the below method to do so.

// Convert milliseconds into 'h:mm a' time format
    msToTime(s){
        let ms = s % 1000;
        s = (s - ms) / 1000;
        let secs = s % 60;
        s = (s - secs) / 60;
        let mins = s % 60;
        let hrs = (s - mins) / 60;
        hrs = hrs < 10 ? '0' + hrs : hrs;
        mins = mins < 10 ? '0' + mins : mins;
        console.log(hrs + '  ' + mins);
        return hrs+':' + mins + ':00.000Z';
    }

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .