Question

When i try to rename a file using its last modified date, it is NOT working when using dateformat ="yyyy-MM-dd_HH;mm" for example.

When i use:

dateformat = "dd-MM-yyyy_HH;mm;ss"
dateformat ="dd-MM-yyyy_HH;mm"
dateformat ="MM-dd-yyyy_HH;mm"

it works perfectly, but when trying to use year as first parameter it wouldn't rename the files.

        if (rb1.isChecked()) {
            dateformat = "dd-MM-yyyy_HH;mm;ss";
        } else if (rb2.isChecked()) {
            dateformat = "dd-MM-yyyy_HH;mm";
        } else if (rb3.isClickable()) {
            dateformat = "MM-dd-yyyy_HH;mm";
        } else if (rb3.isClickable()) {
            dateformat = "yyyy-dd-MM_HH;mm";
        } else if (rb4.isChecked()) {
            dateformat = "yyyy-MM-dd_HH;mm";
        }
        else if (rb5.isChecked()) {
            dateformat = new SimpleDateFormat("yyyy-dd-MM_HH;mm")
                    .format(new Date());
        } else if (rb6.isChecked()) {
            dateformat = new SimpleDateFormat("yyyy-MM-dd_HH;mm;ss")
                    .format(new Date());
        }

I should NOT have used .isCickable, but .isChecked .....

Was it helpful?

Solution

Use this..

String timeStamp = new SimpleDateFormat("yyyy-MM-dd_HH;mm;ss").format(new Date());

Update: replace the following code snippet...

    if (rb1.isChecked()) {
        dateformat = "dd-MM-yyyy_HH;mm;ss";
    } else if (rb2.isChecked()) {
        dateformat = "dd-MM-yyyy_HH;mm";
    } else if (rb3.isClickable()) {
        dateformat = "MM-dd-yyyy_HH;mm";
    } else if (rb3.isClickable()) {
        dateformat = "yyyy-dd-MM_HH;mm";
    } else if (rb4.isChecked()) {
        dateformat = "yyyy-MM-dd_HH;mm";
    }

    else if (rb5.isChecked()) {
        dateformat = new SimpleDateFormat("yyyy-dd-MM_HH;mm")
                .format(new Date());
    } else if (rb6.isChecked()) {
        dateformat = new SimpleDateFormat("yyyy-MM-dd_HH;mm;ss")
                .format(new Date());
    }
    SimpleDateFormat formatter = new SimpleDateFormat(dateformat);
    String formattedDateString = formatter.format(lastModDate);
    newimgname = formattedDateString + ".jpg";

With...

if (rb1.isChecked()) {
    dateformat = "dd-MM-yyyy_HH;mm;ss";
} else if (rb2.isChecked()) {
    dateformat = "dd-MM-yyyy_HH;mm";
} else if (rb3.isClickable()) {
    dateformat = "MM-dd-yyyy_HH;mm";
} else if (rb3.isClickable()) {
    dateformat = "yyyy-dd-MM_HH;mm";
} else if (rb4.isChecked()) {
    dateformat = "yyyy-MM-dd_HH;mm";
} else if (rb5.isChecked()) {
    dateformat = "yyyy-dd-MM_HH;mm";
} else if (rb6.isChecked()) {
    dateformat = "yyyy-MM-dd_HH;mm;ss");
}

String formattedDateString = new SimpleDateFormat(dateformat).format(new Date());
newimgname = formattedDateString + ".jpg";
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top