I am trying to convert the creationTime attribute of a file to a string with the date format MM / dd / yyyy. I use Java nio to get the creationTime attribute, which is of type FileTime , but I just need the date from this FileTime as a string with the date format specified earlier. As long as I have ...
String file = "C:\\foobar\\example.docx"; Path filepath = Paths.get(file); BasicFileAttributes attr = Files.readAttributes(filepath,BasicFileAttributes.class); FileTime date = attr.creationTime(); DateFormat df = new SimpleDateFormat("MM/dd/yyyy"); String dateCreated = df.format(date);
However, it throws an exception saying that it cannot format the FileTime date object as a date. FileTime seems to be output as 2015-01-30T17:30:57.081839Z , for example. What solution would you recommend to best solve this problem? Should I just use regex on this output or is there a more elegant solution?
java
user2150250
source share