473,395 Members | 1,978 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Time comparison doesnt work...

Relevant part of the code::

//that code wouldnt work ..its purpose is to compare the current time with a give time (in this case italian)
//output of current time is displayed as 0001 (time is 11:42)
//To be precise 2212 output of given time is displayed as 2213 time is 9:00....any ideas??


public static Calendar now2(int hour,int minute,int sec) {
GregorianCalendar calendar2 = new GregorianCalendar();
calendar2.clear();
calendar2.set(Calendar.HOUR_OF_DAY,hour );
calendar2.set(Calendar.MINUTE,minute);
calendar2.set(Calendar.SECOND,sec);
return calendar2;
}


GregorianCalendar calendar = new GregorianCalendar();

calendar.clear();
calendar.get(Calendar.HOUR_OF_DAY);
calendar.get(Calendar.MINUTE);
calendar.get(Calendar.SECOND);

lanng="IT";
int openingh=-1;
int openingm=-1;
int openings=00;
int closingh=-1;
int closingm=-1;
int closings=00;

// int currentime = Integer.parseInt(now("HHMM"));


if (langg.equalsIgnoreCase("IT"))
{
openingh=9;
openingm=00;
closingm=16;
closings=00;

}
if (langg.equalsIgnoreCase("IT"))
{
openingh=9;
openingm=00;
closingm=10;
closings=00;

}

if (langg.equalsIgnoreCase("DA"))
{
openingh=8;
openingm=00;
closingm=15;
closings=00;

}




SimpleDateFormat format = new SimpleDateFormat("HHMM");
System.out.println("To be precise " + format.format(calendar.getTime()));

SimpleDateFormat format2 = new SimpleDateFormat("HHMM");
System.out.println("To be precise " + format2.format(now2(openingh,openingm,openings).ge tTime()));

if (choiceName.equals("Callback")){

if ( calendar.before(now2(openingh,openingm,openings)) && calendar.after(now2(closingh,closingm,closings )))
{
choice.setEnabled(false);
System.out.println("Callback DISABLED");

}
else{
choice.setEnabled(true);}


}
Jul 20 '08 #1
3 1694
I've corrected the code..

but still the output is not completely correct

IT
To be precise 2008-07-20 12:23:55 (correct)
To be precise 2008-07-20 09:00:00 (correct)

updated code:


public static Calendar now2(int hour,int minute,int sec) {
GregorianCalendar calendar2 = new GregorianCalendar();
// calendar2.clear();
calendar2.set(Calendar.HOUR_OF_DAY,hour );
calendar2.set(Calendar.MINUTE,minute);
calendar2.set(Calendar.SECOND,sec);
return calendar2;
}
GregorianCalendar calendar = new GregorianCalendar();

String langg="IT";





System.out.println (langg);
int openingh=-1;
int openingm=-1;
int openings=0;
int closingh=-1;
int closingm=-1;
int closings=0;


if (langg.equalsIgnoreCase("IT"))
{
openingh=9;
openingm=0;
closingm=10;
closings=0;

}

if (langg.equalsIgnoreCase("DA"))
{
openingh=8;
openingm=0;
closingm=15;
closings=0;

}

if (langg.equalsIgnoreCase("ES"))
{

openingh=7;
openingm=0;
closingm=16;
closings=0;

}

SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println("To be precise " + format.format(calendar.getTime()));

SimpleDateFormat format2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println("To be precise " + format2.format(now2(openingh,openingm,openings).ge tTime()));

if (choiceName.equals("Callback")){

if ( calendar.before(now2(openingh,openingm,openings)) && calendar.after(now2(closingh,closingm,closings )))
{
choice.setEnabled(false);
System.out.println("Callback DISABLED");

}
else{
choice.setEnabled(true);
System.out.println("Callback ENABLED, OPTION");
}
}
Jul 20 '08 #2
JosAH
11,448 Expert 8TB
I if ( calendar.before(now2(openingh,openingm,openings)) && calendar.after(now2(closingh,closingm,closings )))
If I read your code correctly (your should've put it between those [ code ] ... [ /code ] tags),
that condition can never be true, the time can never be before opening hours
*and* after closing hours.

kind regards,

Jos
Jul 20 '08 #3
If I read your code correctly (your should've put it between those [ code ] ... [ /code ] tags),
that condition can never be true, the time can never be before opening hours
*and* after closing hours.

kind regards,

Jos

That's correct so it should be an || there instead of &&

int closingm=-1; should be closingh and the clear can be removed from now2

Thanks :-)
Jul 20 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

125
by: Rhino | last post by:
One of my friends, Scott, is a consultant who doesn't currently have newsgroup access so I am asking these questions for him. I'll be telling him how to monitor the answers via Google Newsgroup...
6
by: teddysnips | last post by:
I have a table called WorkItem. It models a chunk of work done during a working day. It has two columns that I'm interested in: Start (smalldatetime) - the TIME the work block is begun...
68
by: Roman Ziak | last post by:
Hello, I just downloaded MS Visual Studio 2005 Express Beta. When I tried to compile existing valid project, I get a lot of warnings like 'sprintf' has been deprecated, 'strcpy' has been...
4
by: matt | last post by:
I am trying to compare a two segments of XML from two seperate files. The two XML files are 1)a message pulled from my private Queue and 2)an XML file that is loaded as an XmlDocument object. So...
3
by: JamesB | last post by:
Hmm, this doesn't seem to work. I am probably tackling it completely the wrong way, but basically I want a function to receive two IP's and a subnet mask and return True if IP1 and 2 are on the...
13
by: Jim Carlock | last post by:
I have over a hundred pictures I would like to present. Is it practical to create and parse an array of pictures, picture paths, et al using server-side scripting to accomplish this? I...
10
by: walterbyrd | last post by:
I don't know if this is a fair comparison or not. Any comments appreciated. - Python is more readable, and more general purpose - PHP has awful backward compatibility - PHP has a lower barrier...
25
by: dennijr | last post by:
ok, shell always used to be easy for me, now its starting to get annoying cause i dont know wats wrong heres the simplist code possible: Private Sub IExplorer_Click() a = Shell("C:\Program...
0
by: =?Utf-8?B?SmVubnlZ?= | last post by:
i have installed AS4.5 and it syncs with the pda phone one time. then the next time i plug in the usb, it says no connection and AS does not automatically start even though it is checked. I try...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.