Question: I am developing an app that loops for several hours or even maybe days and what I want is that it loops past the current day into the next it creates a new file with a new file name.
Can anyone help me with the logic ?
Here is my code:

```
    timedata= new File(timedata)
    String timedatafile=  "/sdcard/timedata"+"-"+formattedDate+".csv";

    if(MsureData.exists()!=true)
{
    timedata.createNewFile();
    Calendar c = Calendar.getInstance();
    String formattedDate = df.format(c.getTime()); 
    // do stuff
}

```

Answer: 
```
int yourdelay=86400000; // delay in millisecond, 24 hours=86400000 millisecond

final Handler handler = new Handler();

handler.post(new Runnable()
{
    @Override
    public void run()
    {
       Calendar c = Calendar.getInstance();
       SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss",Locale.getDefault());
       String formattedDate = df.format(c.getTime());

       String pathfile=  "/sdcard/timedata"+"-"+formattedDate+".csv";
       File filedata= new File(pathfile);

       //if file not exists create new file
       if(!filedata.exists())
       {
          filedata.createNewFile();                

       }

      handler.postDelayed(this, yourdelay);

    }
});

```

***This one form to solve your problem implementing handler to run day by day in the same hour minute and second.***
```
Date currentDate = new Date(System.currentTimeMillis());

```

From this you can get current date of system.