Thursday 15 July 2010

datetime - Summing java.sql.Time objects -


I have a list of timing items (representing the length of a song) that I want to simultaneously add together Looking at the documentation for the object, it seems that the part of the date should be untouched and after 1 millisecond the number of milliseconds will represent the number of milliseconds. A negative value means before 1970.

I have a time object (it is called time ) in the format 00:06:25 i.e. 6 minutes 25 seconds if i Call me date (time.gate time) me guru january 016: 26, who is sensible. However, when I only print the value of getTime () -3215000, which is not fully understood, this value will indicate that the time before January 1, 1970, .. which is it

so when I try to add more than one call (like 00: 03: 35 / -3385000) of getTime () The maximum number of negative numbers is available (-6600000).

So when I try to create a new time object with that value, then let me know at 23:10:00 instead of 09:00.

I created a test job that displays the following output:

  1 January 1970 00:06:25 GMT 1st January 1970 00:03:35 GMT 1st January 1970 00:03:18 GMT 1st January 1970 00:04:22 GMT 1st January 1970 00:03:47 GMT 1st January 1970 00:00 : 00 GMT 1 January 1970 00:21:27 GMT  

Previous time is the sum of 6 times the predecessor

The move is to use toGMTString () to be deprecated () ) The method of time to generate the output string.

Here is the code I used:

  package com.ggl.Testing; Import java.sql.Time; Public Class Editions Runnabal (Private Time [] Population; Public AddDates () {this.songLength = New Time [6]; Long = (6L * 60 + 25) * 1000; Song Length [0] = New Time (Time) ); Time = (3L * 60 + 35) * 1000; song length [1] = new time (time); time = (3L * 60 + 18) * 1000; song length [2] = new time (time) ); Time = (4L * 60 + 22) * 1000; song length [3] = new time (time); time = (3l * 60 + 47) * 1000; song length [4] = new time (time) ); Time = 0 L; song length [5] = new time (time);} @ override public widescreen run (for long amount = 0 l; (int i = 0; i & lt; songLength.length; I ++) {sum + = songLength [i] .getTime (); Println (songLength [i] .toGMTString ());} Time total time = new time (amount); Println (totalTime.toGMTString ());} Public Static Zero Main (String [] Args) {New AddDates (.) Run ();}}  

No comments:

Post a Comment