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;

View Replies


ADVERTISEMENT

Creating TravelTimeRow Inside A Class With Strings For Time - Hours And Minutes

May 13, 2014

I have an application which is doing a fine job of placing the total hours on the interface.

Where I am breaking down is that I am unable to split the string into two distinct groups: hours and minutes

private HtmlElement createTravelTimeRow(ShowSet showSet) {
HtmlElement tr = new HtmlElement(ROW_OPEN, ROW_CLOSE);
HtmlElement td = new HtmlElement(CELL_OPEN, CELL_CLOSE);

[Code].....

I came across something which showed how to split the String but I am still very unsure how to do this.

View Replies View Related

Represent Time Span Of Hours And Minutes Elapsed - Method Is Undefined For Type TEST

Jul 29, 2014

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;

[Code] ....

View Replies View Related

JSP :: Convert Minutes To Hours And Minutes Using JSTL And Java

Sep 19, 2014

I'm fairly new to JSTL. Can I convert the minutes JSTL expression into hours and minutes using a java method. I'm not sure how to go about.

<% CalendarUtilities.getHoursAndMinutes(%> ${minutes} <% ) %>

View Replies View Related

Military Time - Adding Minutes Displaying Correct Time

Feb 9, 2015

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.

for example,

Start Time = 0930
Length = 50 minutes
Endtime = 1020

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);

[Code] ....

View Replies View Related

How To Time While Loop To Execute Every 3 Seconds

Jul 11, 2014

How can I time my while loop to executeevery 3 seconds?

Here is my code:

class Info{
public String name;
public String version;
public String arch;
double CPUSpeed;
};
Info info = new Info();
Info[] queue = new Info[100];

[Code]...

I seem to have done it right, but it doesn't work... What is wrong?

View Replies View Related

Convert Time In Seconds To Hhmmss Format?

Apr 8, 2014

I am trying to convert time in seconds to hhmmss format.How do i get the minutes and seconds.

View Replies View Related

Daily Time Record And Computation Of Hours Work

Aug 13, 2014

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"};

[Code] .....

View Replies View Related

For Loop Program - Increment Hours By 12 And Double Population By 2 Each Time

Oct 3, 2014

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:

Hours: - Population:
0 ------- 1000
12 ----- 2000
24 ----- 4000

I've created the code, but don't understand how to increment hours by 12 and double the population by 2 each time.

public class Population
{
public static void main (String[] args) {
int hours = 0;
int population;

[Code] ....

View Replies View Related

Converting Military Time To Standard Time?

Jan 29, 2014

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;

[code]....

View Replies View Related

Read Amount Of Minutes / Displays Approximate Number Of Years / Days For Minutes

Sep 7, 2014

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.

View Replies View Related

Converting String To Date And Time MYSQL

Apr 8, 2014

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());

[code]....

View Replies View Related

JSP :: Execute Code After Every 10 Seconds

Feb 25, 2014

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)

[code]....

View Replies View Related

Swing/AWT/SWT :: Analog Clock Working But Seconds Repeating In Java

Oct 6, 2014

I made an Analog Clock and its working but when a remove the filloval (Background) the seconds hand keep repeating itself..here is the code

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import javax.swing.JFrame;
import javax.swing.JPanel;

[code]....

View Replies View Related

Snake Game - Refresh Grid Of ASCII Characters Every 0.2 Seconds

Mar 4, 2014

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?

View Replies View Related

Timer Conversion On JApplet - Implement 6 Seconds Delay Before Every Loop

Jul 7, 2014

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++) {

[Code] ....

View Replies View Related

Equals Comparison Does Not Work

Jan 12, 2015

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);}

Attached image(s)

View Replies View Related

File Comparison With 1.6 Million In Each

Mar 14, 2014

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.

View Replies View Related

I/O / Streams :: File Size Comparison

May 20, 2014

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?

View Replies View Related

Online Shopping Price Comparison

Jan 20, 2015

I want the code for comparing the price of product on different online shopping site ...

View Replies View Related

Mastermind Game - Comparison Event

Jan 14, 2015

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){

[Code] .....

The problem is when the code is for example

ACDD

and the player guess is

ADDD

Result is

2 right spot right color

1 right color wrong spot

It have to be

2 right spot right color

0 right color wrong spot

View Replies View Related

Document Comparison / Proof Reading

Feb 14, 2014

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...

View Replies View Related

Two Strings - Equals Comparison Fails

Jan 12, 2015

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);}

View Replies View Related

String Comparison When Both Values Are Null

Aug 5, 2014

In Java is there  a method which  I can use to compare two Strings where in if both the values are null, they should be considered as equal?

View Replies View Related

Comparison Of Array Values From Other Private Class

May 24, 2014

I got a task from my teacher and the restriction is we are not able to modify this class (and that is the problem).This is the given class:

public class Jobs {
private intcounter= 0;
private final intnoElements= 20;
private final int[]a= { 11, 28, 31, 42, 49, 66, 67, 75, 89, 100, 102, 103, 114, 125, 130, 135, 140, 145, 150, 155 };
private final int[]s= { 20, 9, 7, 6, 12, 15, 4, 7, 30, 22, 11, 45, 20, 6, 6, 5, 5, 5, 5, 5 };

[code]...

I need to compare some of the values of the given arrays. For example: if(a[4]<a[2])... etc.

How can I do these kind of operations to a private array? I have to compare the values in an new classPS: I have to compare the values in a new class

View Replies View Related

Second Counter To Minutes

Apr 7, 2014

I have a timer where it counts down from 300 to 0 then does something. But I want the display for the clock to show the time in minutes. I tried:

double showTimeLeft = timeLeft / 60;
o.setDisplay(String.format("%.2f", showTimeLeft) + " Minutes");

But Every so many seconds it skips like:

Time = 3.38
Time = 3.37
Time = 3.35
Time = 3.34

It skipped 3.56

How to do this right?

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved