Time Comparison - Converting To Seconds / Minutes And Hours
Apr 27, 2013
I want to compare two times. What I am doing is
java.util.Date date = new java.util.Date();
java.sql.Time cur_time = new java.sql.Time(date.getTime());
/*this is my database connectivity code from where I am getting second date that I am comparing. This is right. Don't bother it.
Connection c= ConnectionManager.getConnection();
String sql = "select t from datesheet where subjectCode=? and sessional=? and d=?";
PreparedStatement ps = c.prepareStatement(sql);
ps.setString(1,subjectCode);
ps.setString(2,sessional);
ps.setDate(3,cur_date);
ResultSet rs = ps.executeQuery();*/
if(rs.next())
{
java.sql.Time t = rs.getTime("t");
long diff = cur_time.getTime()-t.getTime();
}
Then I am converting it to seconds, minutes and hours, but the problem is time that we get from cur_time.getTime() has more digits than time that we get from t.getTime(), so it is always greater than t.getTime() even when it is not.
long seconds = (diff/1000)%60;
long minutes = (diff/60000)%60;
long hours = (diff/(60*60*1000))%24;
I am trying to run a class with a client code and I get the following error
The method add(TimeSpan) is undefined for the type TEST
Why i get this error?
package timespan; // Represents a time span of hours and minutes elapsed. // Class invariant: minutes < 60 public class TimeSpan { private int hours; private int minutes;
I am working on an assignment that I can't seem to figure out the final part to. The program takes in course data such as the time the class starts and how long it lasts. The time is in military time (0000 - 2400)
I need the output time to be the time the class started, plus the length of the class, and displayed in military time.
I can't for the life of me figure out how to do this. I have gotten a program that works for this time and minutes, and displays the correct 1020. But when I change the information to say
Start time: 0700 Length = 90 minutes
I get:
Endtime = 90
90 is technically correct, the way the formula is setup, but I need it to display 0900 not 90.
Here is the code that I have. Be easy, I'm still learning, and this is just the file I created to get the formula to work. Also, the verbose in here is just for my own debugging to make sure values should be what I'm expecting them to be.
public class calc { public static void main(String[] args) { double hours, minutes, length; double temp; int time = 2400; hours = time / 100; System.out.println("Hours are: " + hours);
import java.io.*; public class workhours{ public static void main (String args[]){ try{ BufferedReader breader=new BufferedReader(new InputStreamReader(System.in)); String days[]={"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
So I need to make a for loop for this problem: A certain type of bacteria doubles its population every twelve hours. If you start with a population of 1000, how many hours will it take for the population to exceed 1,000,000? Output needs to be in table format, such as:
I have two classes. time_runner is used for testing my code.
This is what I'm using to test my code:
class time_runner { public static void main(String str[]) throws IOException { Time time1 = new Time(14, 56); System.out.println("time1: " + time1); System.out.println("convert time1 to standard time: " + time1.convert()); System.out.println("time1: " + time1); System.out.print("increment time1 five times: "); time1.increment();
[code]....
The two constructors are "Time()", which is the default constructor that sets the time to 1200, and "Time(int h, int m)" Which says If h is between 1 and 23 inclusive, set the hour to h. Otherwise, set the hour to 0. If m is between 0 and 59 inclusive, set the minutes to m. Otherwise, set the minutes to 0. Those are my two constructors that I pretty much have down. The three methods however I'm having trouble with. The "String toString()" Returns the time as a String of length 4. The "String convert()" Returns the time as a String converted from military time to standard time. The "void increment()" Advances the time by one minute.
public class Time { private int hour; private int minute; public Time(int h, int m) { if(h > 1 && h < 23) hour = h;
I need to write a simple program that reads an amount of minutes and displays the approximate number of years and days for the minutes. For simplicity, assume a year has 365 days and the resulting amount of days is a whole number.
In my java file I made Strings of date and time, but my MYSQL database needs Date and Time of course. I've tried to convert them, but I keep getting this exception: org.apache.jasper.JasperException: java.lang.NumberFormatException: For input string: "2013-02-20"
public class Vogel { static final String url = "jdbc:mysql://localhost:3306/turving"; public static void Insert(String datum, String tijd, String plaats, String spotternaam, String vogelsoort) { try { SimpleDateFormat format = new SimpleDateFormat("YYYY-MM-DD"); SimpleDateFormat formatt = new SimpleDateFormat("HH:MM:SS"); java.util.Date parsed = format.parse(datum); java.util.Date parsedd = formatt.parse(tijd); java.sql.Date sql = new java.sql.Date(parsed.getTime()); java.sql.Time sqll = new java.sql.Time(parsed.getTime());
I want to execute my jsp code to compare two dates after every 10 seconds if user enter date and current sys date are equal it will send the mail to the user automatically. Below is my jsp code
this if condition i want to check the date after every 10 seconds and when two dates are equal it will send the mail using below mail code
if(ExpcReDt.compareTo(dateStr)>0) { out.println("Expected return date is greater than current date"); } else if(ExpcReDt.compareTo(dateStr)==0)
I am busy programming a clone of the popular phone game they had on Nokia cellphones a long time ago called Snake II but since I know very little about programming I will be using ASCII graphics instead of a 2D graphics engine.
My idea for implementation is having a main class called game which should refresh a grid of ascii characters every, say 0.2 seconds. Then I have another class called Dot. Each Dot object has x and y coordinates, and a direction in the x and y planes (dirx = -1 means left, dirx = 1 means right, diry = 1 means up, diry = -1 means down, and obviously the snake cant move the diagonals)
The Game class prints a "*" symbol where the Dot is, and what I'm trying to do is get the screen to refresh (I think I need to use the sleep() function for this to slow the game down to a reasonable pace), and go in the direction it is supposed to go.
(I haven't programmed this in yet but the snake will be an array of Dot, and at each refresh Dot at position 0 will pass it's coordinates and direction to Dot at position 1, Dot1 to Dot2, Dot2 to Dot3, etc.
Here's my code so far:
A first class called Game.
Java Code: //Not done yet but this is the start to my game of Snake. Basically the class Game generates a Grid of ASCII characters
import java.util.Scanner; public class Game { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); final int WIDTH = 79;
[Code] .....
My problem now is that I am taking input from the Scanner class. What it does is wait for my input, then it goes on to executing the rest of the code in other words refresh the ASCII grid. This is a problem because I need the snake to keep moving at constant pace while listening to the keyboard.
How can I get my while loop to keep going (i will add a sleep() function later) while listening to the keyboard without stopping?
So I'm trying to make an applet and I found that Thread.sleep() to simply delay is a bad idea.
I'm not sure how to use the Timer class to implement a same version of sleep() to delay 6 seconds. I am trying to do this in a for loop to delay before every loop. How can I implement this?
This code is after the init() method. For simplicity I didn't include. Assuming I did:
Timer t = new Timer(6000, null); public void actionPerformed(ActionEvent e) { try { URL rsUrl = new URL("http://rscript.org/lookup.php?type=namecheck&name=" + n1); BufferedReader br = new BufferedReader(new InputStreamReader(rsUrl.openStream())); for (count = 0; count < maxCount; count++) {
All I am trying to do is to make a section of code execute if two strings are equal. The two strings are userId and "A001062". When I use the debugger in Eclipse, I can see the value of userId as "A001062" but whatever string comparison I try never evaluates to true. I have tried
userId=="A001602" userId.equals("A001602") "A001602.equals(userId) Assigning A001062 to a string called AAA and comparing userId to AAA
My code is as follows. I have also attached a screen shot from the Eclipse Debugger which makes me think the string comparison should succeed. I never see the debugger execute the print line nor do I see the print line on the JBOSS console.
String userId = StringUtils.trim(nextLine[HR_USER_ID]); String AAA="A001062"; if (userId.intern().equals(AAA.intern())) {System.out.print("MKP1: " + userId+"-"+managerId);} if (userId.compareTo("DTS0428")==0) {System.out.print("MKP2: " + userId+"-"+managerId);}
I have two big text file with approx 16 Lakh (1.6 Million) records in each. Both file contains Strings in each line. I would like to compare two files and find the descripencies and print them into separate file.
I would like to create a component to detect the file being modify before process.is it the right way to detect the file modification based on file size value?
Below are the flow:
1. Get the file size of a file 2. Used file size value encrypt it with MD5 algorithm, and say it generated us encrypted value "0123sdf" 3. to avoid user modify the file content, before file process, we take the file and do the encryption with md5 again, if it return value "0123sdf", then we are sure it doesn't have modification.
my question: a. is it the right approach to detect file modification? b. what the library advise to use or using java.security.DigestInputStream will do?
I'm not so new to java i know the basics. I want to make a mastermind game. Just for training purpose.
Now i am at the comparison phase where it is comparing your chosen "colors" with the actual "color code"
This is my code for that part:
guesChars is a char array of 4 of the actual code readGuess is a string of 4 of which the players has filled in the console goodGuess is a char at the right position with the right "color" avgGues is a char with the right "color" at the wrong position
Java Code:
for(int i = 0; i < guessChars.length; i++){ for(int ii = 0; ii < readGuess.length(); ii++){ if(readGuess.charAt(ii) == guessChars[i]){ if(ii == i){
So - working on some new document composition tasks today, and realised my life would be made easier if I could have an application to allow me to compare two documents and highlight the differences...I know I could use a number of other tools, even word compare but it would be more fun if I could do it myself. Plus - there's the thrill of using non-approved technology at my workplace...I'm a maverick.
Just looking for the high level steps I should go through in creating an application which could be delivered to users in my team as an executable file (I have admin rights to my works laptop, but my direct reports do not have this on theirs) so would need to be able to run the app without installing if possible...
All I am trying to do is to make a section of code execute if two strings are equal. The two strings are userId and "A001062". When I use the debugger in Eclipse, I can see the value of userId as "A001062" but whatever string comparison I try never evaluates to true. I have tried
userId=="A001602" userId.equals("A001602") "A001602.equals(userId) Assigning A001062 to a string called AAA and comparing userId to AAA
My code is as follows. I have also attached a screen shot from the Eclipse Debugger which makes me think the string comparison should succeed. I never see the debugger execute the print line nor do I see the print line on the JBOSS console.
String userId = StringUtils.trim(nextLine[HR_USER_ID]); String AAA="A001062"; if (userId.intern().equals(AAA.intern())) {System.out.print("MKP1: " + userId+"-"+managerId);} if (userId.compareTo("DTS0428")==0) {System.out.print("MKP2: " + userId+"-"+managerId);}