I'm using a .split() function to return the time from an AWSDateTime type.
I'm looking to set a variable using the split string, I need the time to only show hours & minutes & not seconds.
AWSDateTime from DB -
startDateTime = '2022-11-1111:11:11.482Z'
Variable to be set in HH/MM -
this.startTime = this.edit.onHold[0].startDateTime.split('T')[1];
I'm currently getting the value returned of -
11:11:11.482Z
but what I'm looking for is
11:11
Is there a way using the .split() method to be more specific and remove the seconds. I need this as I'm splitting the variable to be used as a 'time' type on the HTML and currently this doesn't work.
CodePudding user response:
With split, there you go
'2022-11-11T11:11:11.482Z'.split("T")[1].split(":").slice(0, 2).join(":")
However I feel regex are usually more efficient
'2022-11-11T11:11:11.482Z'.match(/\d{1,2}:\d{1,2}/)[0]