How to calculate total time the sensor is staic or dynamic?

I have accerlometer modules,a which is connected to esp8266

I am already taken the values when device is moving and static(read raw data from register).

Its given in the "If" condition,

How can i calculate the total time ( second or minute) when device is static or dynamic ?

#include <Ticker.h>
#include <Wire.h>

#include <MPU6050.h>
int  startTime=0,endTime=0;
int i=0;
int j=0;
double x;
double y;
int SCL_PIN=26;  
int SDA_PIN=25;  
MPU6050 mpu;
Ticker blinker;

void changeState()
{
Vector rawAccel =mpu.readRawAccel();

x =  rawAccel.XAxis;
y = rawAccel.YAxis;

if(x>250&&x<1000||y>64000)  // static values
 { 
 i++;
 Serial.print("static");
  Serial.print("total time in second ");
 Serial.println(i);
 }

 if(x>900||y<500)    // dynamic values
 {
   j++;
   Serial.print("dynamic");
   Serial.print("total time in second");
   Serial.println(j);
   
 }

}


void setup()
{
 Serial.begin(9600);
 Serial.println("Initialize MPU6050");

  while(!mpu.beginSoftwareI2C(SCL_PIN,SDA_PIN,MPU6050_SCALE_2000DPS, MPU6050_RANGE_2G))
  {
    Serial.println("Could not find a valid MPU6050 sensor, check wiring!");
    delay(500);
  }
 blinker.attach(.5, changeState);

}

i am tried this code ,but some values are missing, any other way?




void loop()
{

}

Adding up the millis() used? Maybe I misunderstood your question.