Results 1 to 2 of 2
- 06-10-2010, 08:58 AM #1
Member
- Join Date
- May 2010
- Posts
- 22
- Rep Power
- 0
how to print the from and to datetime
this is our code
this is our outputJava 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; import java.util.Map; import java.util.HashMap; public class Speedfinal { private static PreparedStatement preparedStatement; private static ResultSet rs; private static ResultSet rss; 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; PreparedStatement preparedStatement1 = null; Connection conn=null; long Total=0; long Totals=0; String disHour=""; String disMinu=""; String disSec=""; ArrayList arr = new ArrayList(); ArrayList arr1 = new ArrayList(); Integer sums = null; 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, Longi, Lat, speed from xydata where objectId= '18' AND clientId = '1' AND gpstime >= '2010-06-08 00:00:00' AND gpstime <= '2010-06-08 23:59:59' AND speed='0'"); rs = preparedStatement.executeQuery(); long totalTimeInMillis=0; Set<String> dates = new HashSet<String>(); ArrayList<Timestamp> l=new ArrayList<Timestamp>(); ArrayList<Timestamp> ll=new ArrayList<Timestamp>(); ArrayList<Integer> m=new ArrayList<Integer>(); ArrayList<Long> n=new ArrayList<Long>(); ArrayList<String> a=new ArrayList<String>(); Map <String, Long> datesAndTotal = new HashMap<String, Long>(); DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); Timestamp t1 = null; Timestamp t2 = null; int count = 0; long sum = 0; while ( rs.next() ) { String Longi=rs.getString("Longi"); String Lat=rs.getString("Lat"); String gpstime = rs.getString("GpsTime"); if (dates.add(gpstime)) { Date d2 = rs.getDate(1); t2 = rs.getTimestamp(1); nano = t2.getSeconds(); //System.out.println(t2); count++; if (t1 == null ) { System.out.println(t2); //l.add(t2); } else { totalTimeInMillis = (t2.getTime() - t1.getTime()) / 1000; String dateString = df.format(t2); if (datesAndTotal.containsKey(dateString)) { if(totalTimeInMillis<=61) { m.add((int)totalTimeInMillis); } for (int y=0; y<m.size();) { sum+=m.get(y); y++; } sum+= (datesAndTotal.get(dateString))/-1; if(totalTimeInMillis>61) { n.add(sum); l.add(t1); ll.add(t2); int hours = (int) (sum / 3600), remainder = (int) (sum % 3600), minutes = remainder / 60, seconds = remainder % 60; disHour = (hours < 10 ? "0" : "") + hours; disMinu = (minutes < 10 ? "0" : "") + minutes; disSec = (seconds < 10 ? "0" : "") + seconds; // System.out.println("Total Time=>" +disHour +":"+ disMinu+":"+disSec+ " hh:mm:ss"); System.out.println("From ["+t1+"] To ["+t2+"] is: "+disHour +":"+ disMinu+":"+disSec+ " hh:mm:ss"); // System.out.println("GPSTime====================================== "); // System.out.println("start date " + "["+t2+"]" + " end date " + "["+t1+"]"); } } datesAndTotal.put(dateString, sum); } t1 = t2; } } } int hours = (int) (sum / 3600), remainder = (int) (sum % 3600), minutes = remainder / 60, seconds = remainder % 60; disHour = (hours < 10 ? "0" : "") + hours; disMinu = (minutes < 10 ? "0" : "") + minutes; disSec = (seconds < 10 ? "0" : "") + seconds; System.out.println("Total Time=>" +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(); } } }
2010-06-08 00:00:56.0
From [2010-06-08 14:30:49.0] To [2010-06-08 14:32:49.0] is: 14:28:53 hh:mm:ss
From [2010-06-08 22:04:09.0] To [2010-06-08 22:06:10.0] is: 22:00:13 hh:mm:ss
From [2010-06-08 22:11:42.0] To [2010-06-08 22:15:43.0] is: 22:05:45 hh:mm:ss
From [2010-06-08 22:18:17.0] To [2010-06-08 22:22:18.0] is: 22:08:19 hh:mm:ss
From [2010-06-08 22:36:46.0] To [2010-06-08 22:38:47.0] is: 22:22:47 hh:mm:ss
From [2010-06-08 22:38:47.0] To [2010-06-08 22:40:47.0] is: 22:22:47 hh:mm:ss
From [2010-06-08 22:42:48.0] To [2010-06-08 22:47:38.0] is: 22:24:48 hh:mm:ss
From [2010-06-08 22:47:38.0] To [2010-06-08 22:51:16.0] is: 22:24:48 hh:mm:ss
From [2010-06-08 22:52:59.0] To [2010-06-08 22:55:00.0] is: 22:26:31 hh:mm:ss
From [2010-06-08 22:59:01.0] To [2010-06-08 23:01:01.0] is: 22:30:32 hh:mm:ss
84520
Total Time=>23:28:40 hh:mm:ss
i need this type of output
From [2010-06-08 00:00:56.0] To [2010-06-08 14:30:49.0] is: 14:28:53
hh:mm:ss
From [2010-06-08 14:32:49.0] To [2010-06-08 22:04:09.0] is: 22:00:13 hh:mm:ss
From [2010-06-08 22:06:10.0] To [2010-06-08 22:11:42.0] is: 22:05:45 hh:mm:ss
...
please see the datetime for both output then only u can understand
how do i change to get the above output(rearrange to print the datatime)
thanks in advanceLast edited by baktha.thalapathy; 06-10-2010 at 09:12 AM.
- 06-10-2010, 09:58 AM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Similar Threads
-
how to print
By anilkumar_vist in forum New To JavaReplies: 0Last Post: 03-18-2010, 02:23 PM -
datetime on a jtextfield
By devstarter in forum New To JavaReplies: 1Last Post: 03-02-2010, 01:08 PM -
How to highlight a particular day in DateTime / Calendar widget?
By Mitja in forum SWT / JFaceReplies: 2Last Post: 08-05-2009, 11:00 AM -
cant get to print...
By chango77745 in forum New To JavaReplies: 0Last Post: 02-13-2009, 06:04 AM -
Print the text file and print preview them
By Java Tip in forum java.awtReplies: 0Last Post: 06-22-2008, 11:04 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks