File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes to compare time including AM and PM Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "to compare time including AM and PM" Watch "to compare time including AM and PM" New topic
Author

to compare time including AM and PM

preethi Ayyappan
Ranch Hand

Joined: Oct 04, 2007
Posts: 518
Hi,
In my project, if a customer calls an agent,his time matches with the server time.If the calling time is between 9.00 AM to 6.00 PM the welcome message will be played.If the calling time is between 6.00 PM to 9.00 Am,the message agents logged off should be played.I tried the following.

Here i have checked whether my time 11.49 AM > 9.00 AM and 11.49 AM < 6.00 PM.But nothing is displayed.because it is not taking the AM and PM.It is just comparing 11.49 < 6.00.How can i compare the AM and PM?please help me to solve this.

Thanks.
Kuladip Yadav
Ranch Hand

Joined: Jul 30, 2008
Posts: 162

Try this

preethi Ayyappan
Ranch Hand

Joined: Oct 04, 2007
Posts: 518
Thank you so much.your code helps me.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 9939
    
    6

according to the api, you could also do this:

int hour = calendar.get(Calendar.HOUR_OF_DAY);

which uses a 24 hour clock. you could then check for > 9 and < 18


Never ascribe to malice that which can be adequately explained by stupidity.
Kuladip Yadav
Ranch Hand

Joined: Jul 30, 2008
Posts: 162

Originally posted by fred rosenberger:
according to the api, you could also do this:

int hour = calendar.get(Calendar.HOUR_OF_DAY);

which uses a 24 hour clock. you could then check for > 9 and < 18


That is better solution.

Moiz Randhikpurwala
Greenhorn

Joined: Apr 30, 2010
Posts: 1
Hi how do i extend the logic to support three time zone.. e.g. 2 to 8 i display one message.. 8 to 16 another .. 16 to 24 another messages.. could you please help give n example.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32599
    
    4
Welcome to the Ranch

Do the documents for DateFormat and its subclasses help? You can put in fields for a timezone.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: to compare time including AM and PM
 
Similar Threads
How to compare (Hour) with actual new Date() ?
Java help!!!!
Problem in updating Time
Exception: Server redirected too many times (20)
Java.util.Calendar