Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

to compare time including AM and PM

 
preethi Ayyappan
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 162
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this

 
preethi Ayyappan
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you so much.your code helps me.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12183
34
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Kuladip Yadav
Ranch Hand
Posts: 162
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49733
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Do the documents for DateFormat and its subclasses help? You can put in fields for a timezone.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic