Im trying to send time variable from LWC javascript To apex but not able to do that because of the format. what is the correct format in which I can send the time variable. Tried sending in the following format



this.currenttime = "12:23:05";
submitB({ starttime : this.currenttime)}


public static void newTimeCharge(Time starttime)

what is the proper format?


Set current time as time only instead of string

 currenttime = new Date().getTime();
 submitB({ starttime : this.currenttime})

Second Option: You can change parameter type from Time to String in the apex class and parse it their in apex using newInstance method of Time class by splitting the string using ':' and pass it as integer value in the function

Time.newInstance(Integer hour, Integer minutes, Integer seconds, Integer milliseconds).
  • Please reverse the order of your solutions since the second is the one that solves the asked question. – Phil W Jun 2 at 7:01
  • 1
    Also in the Date-based solution, please remove the "today" variable - you didn't show it consistently, it is "now" not "today" and you can easily inline it. Finally, it would be far better to show Date-based handling of a hard-coded date since the OP shows that themselves. – Phil W Jun 2 at 7:04
  • 1
    Thanks Phil, updated as per your comments. I have not used hardcoded string because the variable name is currentTime so it should be the dynamic current time and not the hardcoded one. I assumed that in the question hardcoded value is just for example/reference purpose to know about the actual format. – Ankur Gupta Jun 2 at 7:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.