Hold a push button

Hai... totally newbie here.
Im running on simple project to power up led for 10s.
Im using a push button (NO).
I need to power up the LED for 10s while the button is push.

  1. Press push button (hold)
  2. LED ON . (only for 10s)
  3. LED OFF.
  4. push button release.

if push button is push less then 10s (ie, 2s)... the LED only ON for 2s.

What function should i use.
Thank you in advance.

Moved your topic to it's current location / section as it is more suitable.

Could you take a few moments to Learn How To Use The Forum.
Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.

I would suggest you look at several of the examples that come with the IDE. You can look at BlinkWithoutDelay to learn how to track elapsed time (like 10s) without blocking your code. You can look at the button press examples to learn how to wire up a button and detect the state of the button.

Give it a try. If/when you get stuck, post your code, the errors and people will help

#define PUSHED                 LOW
#define LEDon                  HIGH
#define LEDoff                 LOW
#define enabled                true
#define disabled               false

bool ledTimingFlag           = disabled;

const byte myLED             = 13;
const byte mySwitch          = 2;

byte lastState;

const unsigned long interval = 10 * 1000ul;
unsigned long ledMillis;
unsigned long switchMillis;
unsigned long currentMillis;

void setup()
{
  pinMode(myLED, OUTPUT);
  digitalWrite(myLED, LEDoff);

  pinMode(mySwitch, INPUT_PULLUP);

} //END of setup()

void loop()
{
  currentMillis = millis();

  checkSwitches();

  if (ledTimingFlag == enabled && currentMillis - ledMillis >= interval)
  {
    digitalWrite(myLED, LEDoff);
  }

} //END of loop()

void checkSwitches()
{
  if (currentMillis - switchMillis < 50)
  {
    return;
  }

  switchMillis = currentMillis;

  byte currentState = digitalRead(mySwitch);

  if (lastState == currentState)
  {
    return;
  }

  lastState = currentState;

  if (currentState == PUSHED)
  {
    digitalWrite(myLED, LEDon);

    ledMillis = currentMillis;

    ledTimingFlag = enabled;
  }

  else
  {
    digitalWrite(myLED, LEDoff);

    ledTimingFlag = disabled;
  }

} //END of checkSwitches()

EDIT
Updated sketch