要自定义格式化FileTime,您可以使用SimpleDateFormat类来格式化日期和时间。以下是一个示例代码,演示如何将FileTime格式化为指定的日期和时间格式: ```java import java.nio.file.attribute.FileTime; import java.text.SimpleDateFormat; import java.util.Date; public class FileTimeFormatter { public static void main(String[] args) { // 获取当前时间 FileTime fileTime = FileTime.fromMillis(System.currentTimeMillis()); // 创建SimpleDateFormat对象,指定日期和时间格式 SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // 将FileTime转换为Date对象 Date date = new Date(fileTime.toMillis()); // 使用SimpleDateFormat格式化Date对象 String formattedDate = dateFormat.format(date); // 打印格式化后的日期和时间 System.out.println("Formatted FileTime: " + formattedDate); } } ``` 在上面的示例中,我们首先获取当前时间的FileTime对象。然后,我们创建一个SimpleDateFormat对象,并指定日期和时间的格式。接下来,我们将FileTime对象转换为Date对象,并使用SimpleDateFormat对象格式化Date对象。最后,我们打印格式化后的日期和时间。 您可以根据需要自定义日期和时间的格式。有关SimpleDateFormat支持的日期和时间格式的更多信息,请参阅Java文档。