Results 1 to 3 of 3
- 05-24-2010, 11:36 AM #1
Member
- Join Date
- May 2010
- Posts
- 22
- Rep Power
- 0
calculate time diff for particular time period
i got the output-> 08:34:00 hh:mm:ssJava Code:package tcplistener; import java.sql.Connection; import java.sql.Date; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Timestamp; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.HashSet; import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; import javax.naming.NamingException; public class testing1 { 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 12:20:40' AND a.gpstime <= '2010-05-13 13:14:08' 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>(); Date d1=null; Timestamp t1 = null; Timestamp t2 = null; int count = 0; while ( rs.next() ) { String gpstime = rs.getString("GpsTime"); //System.out.println("Time in minutes: " + diffSeconds+ " seconds."); if (dates.add(gpstime) ) { //System.out.println(rs.getTimestamp(1)); Date d2 = rs.getDate(1); System.out.print(d2); 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(d1); 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; l.add((diffSeconds < 80) ? (int) diffSeconds : (int) (diffMinutes % 60)); } } 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(); } } }
but i need the separate total time for date
2010-05-11->get the time and count the total time(output)
2010-05-12->get the time and count the total time(output)
2010-05-13->get the time and count the total time(output)
any body having idea
thanks in advanceLast edited by baktha.thalapathy; 05-24-2010 at 11:47 AM. Reason: edit
- 05-24-2010, 11:43 AM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,413
- Blog Entries
- 7
- Rep Power
- 17
- 05-24-2010, 04:10 PM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
NetBeans added it by default. I hate that, waste my space...
Similar Threads
-
JAVA Programmers Wanted - Full-Time and Part-Time Positions open
By javatrek2020 in forum Jobs OfferedReplies: 3Last Post: 08-23-2011, 12:46 PM -
Class Time - represents time of day
By verbazon in forum New To JavaReplies: 1Last Post: 04-13-2009, 01:06 AM -
first time
By oiballab in forum IntroductionsReplies: 2Last Post: 12-18-2008, 01:11 PM -
i click on it,then first time error page comes,second time click then product page co
By 82rathi.angara in forum New To JavaReplies: 21Last Post: 08-01-2008, 11:13 AM -
signing applets for a period of time
By sandeepk84@gmail.com in forum Java AppletsReplies: 0Last Post: 12-04-2007, 01:34 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks