I want to convert a sObject query response parameter to a Time object which will be displayed in the front-end, and I am a bit confused since there is no method valueof() in the class Time in Apex like there is in the class Date.

I have used the below method to wrap a sObject to a Visit object.

public static List<Visit> getVisits(List<SObject> objs) {
    List<Visit> visits = new List<Visit>();
    for (SObject obj : objs) {
      Visit visit = new Visit();
        Visit.visitTime= (Time)obj.get('Time__c');
        visit.patientEmail= String.valueOf(obj.get('Patient_Email__c'));

    return visits;

class Visit{
    public Date visitDate;

    public Time visitTime;

    public String patientEmail;
    public String patientName;

    public String visitDescription;

    public String visitName;

But unfortunately the Visit.visitTime= (Time)obj.get('Time__c'); line just converts it into gibberish number string in this format: 900000 Maybe there is some provided method that does this conversion.

1 Answer 1


There is no Time data type in Javascript, so you're getting the number of milliseconds (a timestamp).
Formatted Time component requires an ISO8601 formatted time string, so you could change the type of visitTime to String and then store it as
Visit.visitTime = String.valueOf((Time)obj.get('Time__c'));.
This way you'll get an ISO8601 time string, like 10:40:57.000Z.

Otherwise, if you cannot change the type of visitTime, you could use a Formatted Date Time component.
This component accepts a timestamp as value and if you want to display only the time, you have to set the following attributes: hour, minute and second.

  • Thank you! This is exactly what I needed! Commented Apr 25, 2021 at 10:01

You must log in to answer this question.

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