FTPClient.listFiles 不以秒为单位返回时间

Kir*_*shi 2 java ftp ftp-client apache-commons-net

private static void getFTPFileProperties(FTPClient client,
            String ftpLocation, String pattern) throws IOException {
    FTPFile[] fileList=null;
    fileList = client.listFiles();
    for(int i=0;i<fileList.length;i++)
    {
        FTPFile file= fileList[0];
        Calendar cal = file.getTimestamp();
        DateFormat dateFormater = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println(dateFormater.format(cal.getTime()));
    }
}
Run Code Online (Sandbox Code Playgroud)

我已经编写了上述函数来检索文件详细信息。但不知何故,我正在检索文件中没有秒部分的细节。我检索lastModifiedDate2013-08-08 00:00:00地方作为其实际lastModifiedDate就是2013-08-08 12:53:27 PM

Mar*_*ryl 5

FTPClient.listFiles使用古老的LIST命令。使用该命令,FTP 服务器返回一个类似于 Unixls命令的列表是很常见的。对于旧文件(超过一年),它仅显示具有日期精度的时间戳。

如今,您应该始终使用FTPClient.mlistDir,它使用始终以第二精度检索时间戳的现代MLSD命令

public FTPFile[] mlistDir() throws IOException
Run Code Online (Sandbox Code Playgroud)

当然,除非你连接到一个古老的 FTP 服务器,否则不支持该MLSD命令。

请注意,mlistDir自 Apache Commons Net 3.0 起支持。