Results 1 to 3 of 3
  1. #1
    Join Date
    May 2010
    Posts
    22
    Rep Power
    0

    Default how do get particular date of total time

    Java Code:
    private static PreparedStatement preparedStatement;
        private static ResultSet rs;
        public static void main(String[] args) throws NamingException, SQLException
        {
     
     
            int objectId;
            int clientId;
             DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            // String gpstime = null;
             PreparedStatement preparedStatement = null;
             Connection conn=null;
             long mill;
             long diffSeconds=0;
             long diffMinutes=0;
             try
             {
              Class.forName("com.mysql.jdbc.Driver");
            Connection conn1=DriverManager.getConnection("jdbc:mysql://108.108.8.4:3306/navl?","root", "ajmani@%");
            preparedStatement = conn1.prepareStatement("select gpstime from xydata a inner join fm4features f on a.ID=f.ID where a.objectId= '18'  AND a.clientId = '1' AND a.gpstime > '2010-05-11 00:00:00'  AND a.gpstime < ' AND f.DataId='1' AND f.value = '1'");
            rs = preparedStatement.executeQuery();
            int a = 0;
            int b=0;
             int b1=0;
             int b2=0;
             int x=0;
             float secs = 0;
     
            Set<String> dates = new HashSet<String>();
            ArrayList<Integer> l=new ArrayList<Integer>();
              Timestamp t1 = null;
              Timestamp t2 = null;
              int count  = 0;
     
              while ( rs.next() )
                {
                    String gpstime = rs.getString("GpsTime");
                    
                    
                
                 if (dates.add(gpstime) )
                 {
                     //System.out.println(rs.getTimestamp(1));
                     t2 =   rs.getTimestamp(1);
                     count++;
                   if (t1 == null )
                  {
                       int nano = t2.getSeconds();
                         System.out.println(nano);
                       System.out.println(nano);
                       System.out.println(t2);
                       System.out.println(count);
                  }
     
                  else
                  {
                        
                        mill= (t1.getTime() - t2.getTime())/-1;
     
                        //System.out.println(mill);
                        diffSeconds = mill / 1000;
                        diffMinutes = mill / (60 * 1000);
                        long diffHours = mill / (60 * 60 * 1000);
                        long diffDays = mill / (24 * 60 * 60 * 1000);
                        //System.out.println("\nThe Date Different");
                        //System.out.println("Time in milliseconds: " + mill+ " milliseconds.");
                        System.out.println("GPSTime " +gpstime+ " Time in seconds: " + diffSeconds+ " seconds.");
                        //System.out.println("Time in minutes: " + diffMinutes+ " minutes.");
                        //System.out.println("Time in hours: " + diffHours+ " hours.");
                        //System.out.println("Time in days: " + diffDays+ " days.");
     
                 }
                  t1 = t2;
     
     
                //System.out.println("Time in minutes: " + diffSeconds+ " seconds.");
                if(diffSeconds < 80)
                {
                  b=(int) diffSeconds;
                  System.out.println(b);
                  l.add(b);
     
                }
     
                 else if(diffSeconds > 80)
                {
                    b2=(int)diffSeconds%60;
     
                    System.out.println(b2);
                    l.add(b2);
                }
                
     
                 a++;
                  }
             }
              
              for (int i=0; i<l.size();)
              {
                  secs+=l.get(i);
     
               
                  i++;
                 
              }
                 System.out.println(secs);
                 int hours = (int) (secs / 3600),
                 remainder = (int) (secs % 3600),
                 minutes = remainder / 60,
                 seconds = remainder % 60;
     
                    String disHour = (hours < 10 ? "0" : "") + hours,
                    disMinu = (minutes < 10 ? "0" : "") + minutes ,
                    disSec = (seconds < 10 ? "0" : "") + seconds ;
     
                    if (count < 2)
                    {
                        int se = Integer.parseInt(disSec);
                        String min = (t2.getSeconds() < 10 ? "0" : "") + t2.getSeconds();
                        System.out.println("00" + ":" +  "00" + ":" + min + " hh:mm:ss");
                    }
     
                    System.out.println(disHour +":"+ disMinu+":"+disSec+ " hh:mm:ss");
                
              
             }catch(Throwable th)
             {
               Logger.getLogger(testing1.class.getName()).log(Level.SEVERE, null, th);
             }finally
             {
               if(preparedStatement!=null)
                   preparedStatement.close();
               if(conn!=null)
                   conn.close();
     
             }
        }
    }
    the output

    Java Code:
    GPSTime 2010-05-11 21:00:31.0 Time in seconds: 61 seconds.
    61
    GPSTime 2010-05-12 09:05:26.0 Time in seconds: 43495 seconds.
    55
    GPSTime 2010-05-12 12:00:37.0 Time in seconds: 10511 seconds.
    11
    GPSTime 2010-05-12 12:01:37.0 Time in seconds: 60 seconds.
    60
    GPSTime 2010-05-12 12:02:38.0 Time in seconds: 61 seconds.
    61
    GPSTime 2010-05-12 12:12:06.0 Time in seconds: 568 seconds.
    28
    GPSTime 2010-05-12 12:13:07.0 Time in seconds: 61 seconds.
    61
    GPSTime 2010-05-12 12:14:07.0 Time in seconds: 60 seconds.
    60
    GPSTime 2010-05-12 12:15:07.0 Time in seconds: 60 seconds.
    60
    GPSTime 2010-05-12 12:42:56.0 Time in seconds: 1669 seconds.
    49
    GPSTime 2010-05-12 12:43:57.0 Time in seconds: 61 seconds.
    61
    GPSTime 2010-05-12 20:35:30.0 Time in seconds: 28293 seconds.
    33
    GPSTime 2010-05-12 20:36:31.0 Time in seconds: 61 seconds.
    61
    GPSTime 2010-05-13 09:22:57.0 Time in seconds: 45986 seconds.
    26
    GPSTime 2010-05-13 11:45:22.0 Time in seconds: 8545 seconds.
    25
    i am getting the total time for all date

    i need only the particular date of total time

    2010-05-11-->total time
    2010-05-12->Total time
    2010-05-13->total time

    how do i change the given code to get the above output
    please help me anybody having idea

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

Similar Threads

  1. [SOLVED] time and date
    By Manfizy in forum New To Java
    Replies: 9
    Last Post: 06-02-2009, 11:13 AM
  2. Time and Date
    By Manfizy in forum New To Java
    Replies: 0
    Last Post: 05-27-2009, 12:58 PM
  3. Date/Time Servlet
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-14-2008, 09:34 AM
  4. Time and Date in Java
    By java_fun2007 in forum New To Java
    Replies: 4
    Last Post: 11-06-2007, 07:25 PM
  5. how to get the current date and time
    By valery in forum New To Java
    Replies: 1
    Last Post: 08-03-2007, 06:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •