Check if an object is in a trigger for a certain amount of time

How can I check and see if an object is in a trigger for a certain period of time? I want to perform a certain action if the object is in the trigger for around 2 seconds, and not do the action if it is removed before those two seconds. Thanks!

Use OnTriggerStay() for the collider and then use a float timer that will decrease by Time.time. Then use OnTriggerExit() when the object leaves the collider and reset the float timer.