1

我之前写过一个代码,一旦文件保存在目录中,我就会在其中添加时间戳。现在我希望能够从扩展名 .txt 之后的文件中截断时间戳,注意我的时间戳格式是:_yyyy-mm-dd。

4

2 回答 2

3

如果您在表格中有延期后的日期,则_yyyy-mm-dd可以使用

String strippedFileName = fileName.substring(0, fileName.length() - 11);

或者更好一点

String dateFormatString = "_yyyy-mm-dd";
String strippedFileName = fileName.substring(0, fileName.length() - dateFormatString.length());
于 2012-12-12T23:20:53.400 回答
0

You could also do this:

String trimmed = filename.replaceAll(".{11}$", "");
于 2012-12-12T23:31:48.533 回答