wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes to compare time including AM and PM Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
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: 11351
    
  16

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


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
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: 39053
    
  23
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://aspose.com/file-tools
 
subject: to compare time including AM and PM