Serial Reading within a Certain Times Arduino

I want to read the existing serial data, in less than 2 seconds there is already serial data then it will go on next process. More than or equal 2 seconds there is no data in the serial, it will continue in the next process. Here is what i try:

const unsigned long timeout = 2000;

void receive_data() {
unsigned long startTime;
char getdata;
String input = "";
String Id;
String Data;  
startTime= millis();

do {
while (Serial.available() > 0) {
getdata = Serial.read();
input += getdata;}
input.trim();
Id = input.substring(0, 1);
Data = input.substring(2);

if (Id == "1") {
  if (Data == "ACK") {
    accept();
  } else if (Data == "NACK") {
    reject();
  }
  startTime= millis();
}

input = "";
} while ((millis() - startTime) < timeout);}

Anyone can help me to make the code for that? Thank You.