0

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

hh:mm:ss
12:23:05
T12:23:05Z
12:23:05.000Z
T12:23:05.000Z

.js

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

apex

public static void newTimeCharge(Time starttime)

what is the proper format?

0

1 Answer 1

2

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).
3
  • Please reverse the order of your solutions since the second is the one that solves the asked question.
    – Phil W
    Jun 2, 2021 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, 2021 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. Jun 2, 2021 at 7:26

You must log in to answer this question.

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