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: 
Save the current date in a variable and include c.getTime() in the loop, when it differs from the current date just replace the value in the variable and create a new file.

```
//new date object initialized to current date
Date currentDate = new Date(); 
Calendar c = Calendar.getInstance();
//loop indefinately
while(true){
    if(!c.getTime().equals(currentDate)){
        //create a new file and set the current date
        currentDate = c.getTime();
    }
}

```
```
Date currentDate = new Date(System.currentTimeMillis());

```

From this you can get current date of system.