Tastybrownies
Tastybrownies

Reputation: 937

Java Files.getLastModifiedTime Returning Unexpected Result

I'm writing a program that goes through files in a directory and checking each file's last modified date and comparing it with another variable. If the variable matches then I copy said file. I thought this was going to work like a charm but the last modified date being returned seems to be incorrect or there is a weird time zone thing happening.

I'm in the middle of a loop and the file currently being looked at is from 2014-08-18 and was actually last modified at 11:58 PM on that date but the getLastModifiedTime returns 2014-08-19T03:58:37.685611Z. So what gives???? Is this some kind of wacky time off set that I need to handle? This is important because if the last modified date is not accurate I won't know which file to copy....Anyone immediately know what's wrong? This is my first time using this way of iterating through files so I may be missing something.

//Creating a DirectoryStream inside a try-with-resource block
            try (DirectoryStream<Path> ds = 
              Files.newDirectoryStream(FileSystems.getDefault().getPath(dir.getAbsolutePath()))) {for (Path p : ds) {

                  String lastMod = Files.getLastModifiedTime(p).toString();

                  String[] splitDte = lastMod.split("T");

                  if(dateSrc.equals(splitDte[0].toString()))
                  {


                     File fileToCopy = p.toFile();
                     copyFile(fileToCopy,

                    tempWorkingDir + "\\" + addLeadingZero(logM, 2) + ""
                            + addLeadingZero(logDy, 2) + "\\" + fixedValue
                            + "\\" + logType + "\\"

                    );
                     fileCountProcsd++;


                  }

             }

            } 
            catch (IOException e) 
            {
               e.printStackTrace();
            }

Upvotes: 1

Views: 504

Answers (1)

user207421
user207421

Reputation: 310980

The Z indicates that the date is expressed in GMT.

Upvotes: 2

Related Questions