How do I detect a 'timed' button release?

Problem: I need the user to hold a button down for 3 seconds, if they let go before the 3 seconds is up an error message will appear.

Question: How do I go about detecting if the user has lifted off the button within the 3 seconds and trigger an error message?

Many thanks in advance.