Button pressing time for analog pins

Hi all,
Im trying to write some code that will count button pressing time for below code,
First state will start after 3 second pressing to button, and other states immediately.
How can I count pressing time 3 second or more?

Thanks in advance.

const int MainLed = 3;
const int button = 2;
boolean previousBtnState = LOW;
boolean nowBtnState = LOW;
int ledMode = 0;
void setup()
{
  pinMode(MainLed, OUTPUT);
  pinMode(button, INPUT);
}
boolean buttonControl(boolean state)
{
  boolean nowBtn = digitalRead(button);
  if (state != nowBtn)
  {
    delay(5);
    nowBtn = digitalRead(button);
  }
  return nowBtn;
}
void ledSet(int state)
{

  if (state == 1)
  {
    digitalWrite(MainLed, HIGH);

  }
  else if (state == 2)
  {
    analogWrite(MainLed, 127);
  }
  else if (state == 3)
  {
    digitalWrite(MainLed, HIGH);
    delay (500);
    digitalWrite(MainLed, LOW);
    delay (500);
  }
}
void loop()
{
  nowBtnState = buttonControl(previousBtnState);
  if (previousBtnState == LOW && nowBtnState == HIGH)
  {
    ledMode++;
  }
  previousBtnState = nowBtnState;
  if (ledMode == 4)
    ledMode = 0;

  ledSet(ledMode);
}

Best you read this first.

DKWatson thank you very much for quick reply,
This is explain how to assigning pressing time to PWM value, I want to start my program when button pressed 3 seconds or more. Even If that explain my problem I couldnt integrate to my code.

Thanks in advance.

This is explain how to assigning pressing time to PWM value

Nonsense.

You want to note when the switch BECOMES pressed. Show the code that does that.

Periodically, if the switch IS pressed, and has been pressed for long enough, you want to do something. Show the code where you try to do that.

Save the millis() value when the button becomes pressed.
Each time through loop(), if the button is still pressed check whether 3 seconds has passed since the button became pressed. If so, then run the code that you want.