Title:
Hi All,

Let me explain the simulating scenario.

There are some files in a FTP server running in my office lan. All files are created today
say 1 file created&modified at 10 AM today and another file created and modified at 1PM today and uploaded to FTP server root folder. I can see the same time stamps in FTP client like FileZilla( and i have verified the same in FTP server folder also).


I am using apache commons net api to connect to FTP server and written code like below.
Both my system where this program is running and FTP server are in same time zone i.e IST ( +5:30 GMT).  In below program i am printing the file modification time stamps to console.

For the both the above files i have created, time is coming correclty but for the first file created before 12 Noon, the year is coming as 2008 instead of 2009.
For second file the time and year is coming correctly.

Note: This behavior is only if call the method
setDefaultUTCTimeZone in first line where i am setting jodadate and java's time zones as UTC.
If i don't call this both Time and Date coming correctly for both files.

In my actual application where i am setting the timezone to UTC. If i change this setting, i need to change entire application code where lot of dependencies are there there and is not practical.

Please suggest me fix If this is real bug. In my application i am using 1.2.1 version of joda date time and verified the same is case even with latest 1.6 joda jar

main (String []args)
{

        
        setDefaultUTCTimeZone();
       
        if(!report.exists())
            report.createNewFile();
       
        BufferedWriter br = new BufferedWriter(new FileWriter(report));
       
        br.write("Start time of the program: "+ new Date().toString()+"\n");
         // initialise the ftp connection
        org.apache.commons.net.ftp.FTPClient ftpClient = new FTPClient();

        // try and connect checking the reply recevied
        ftpClient.connect( "myFTPServerIP" );
      
        // login for the ftp connection
        if ( !ftpClient.login( "username", "password" ) )
            throw new Exception( ftpClient.getReplyString() ) ;

        // set the transfer to binary mode
        if ( !ftpClient.setFileType( FTP.BINARY_FILE_TYPE ) )
            throw new Exception( ftpClient.getReplyString() );


            org.apache.commons.net.ftp.FTPFile[] files = ftpClient.listFiles();
           
            for(FTPFile file : files)
            {
                long time = file.getTimestamp().getTimeInMillis();
               System.out.println("File name :"+file.getName() +" --- Modified date :"+ new DateTime(time).toString()+"\n");
            }
 }
   

// Timezone settings function.......

        public static void setDefaultUTCTimeZone()
        {
            // set the millis generator to generate UTC'd wallclock time
            DateTimeUtils.setCurrentMillisUTCTimeZone( DateTimeZone.getDefault());
          // Note the above method is commented when i am using 1.6 jar as i couldn't find the new method for this deprecated one.


            // default the system joda timezone
           DateTimeZone.setDefault(
DateTimeZone.UTC);

            // default the system joda timezone
             java.util.TimeZone.setDefault(
DateTimeZone.UTC.toTimeZone() );

        }

Thanks for reading the big mail,
Your help is greatly appreciated,
Regards,
--

 

Venkat

------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Joda-interest mailing list
Joda-interest@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/joda-interest

Reply via email to