Convert a string into a 24 hours date and substract hours or minutes

Hello,

My problem is quite precise but keeps bugging me despite extensive researches, maybe you can help.

Let’s say I have
const timeString = “18:30”

How can I convert into a date/time and say substract 35 minutes to it ?

Thank you in advance !

Vnvl

What code have you tried so far? If you are just given a time and no date, you would have to either assume today’s date or pick another date for the time to be able to convert into a date/time. Would you ever have a time like 00:15 and need to subtract 35 minutes from it, so the date would actually become the day before?

Hello,

I think I see what you mean, so I tried this and effectively it is an option :

const date = new Date()
const now = date.getTime()
const before = now - 30000000000

const result = new Date(before).toDateString()

So it works for me. So you cannot only consider “18:30” and then take 1 hour, you have to put a Date in front and then it will work.

Thank you,

Vnvl