This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Journey To Enterprise Agility and have Daryl Kulak & Hong Li on-line!
See this thread for details.
Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Time Class  RSS feed

 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to format the current time using the time class for android java:



Does this look right? The format that I want it to appear is 12.00pm

Thanks!

Kind Regards,
 
Bartender
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mark

I haven't tested this but I think this is what you are after:
 
Mark Do
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks James!!

That did the trick!

Now, from that format, I want to try and see whether or not its the morning, afternoon, or evening.

Do you have a clue how to extract the time from the format to do some checking?

I know that I'll be needing an if else statement, but Im not sure how to extract the information from the actual time displayed.

Thanks!
 
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hm, I don't see an easy way of doing that with android Time, but you could do it fairly easy with Calendar:

 
Mark Do
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but how do I differentiate the afternoon from evening though?

 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Define what 'evening' means, create a Calendar for that time, and compare now to then. Example, if evening starts at 5pm, then I think something like this works:
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just realized you should probably set the milliseconds to 0 for evening as well...
 
Mark Do
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what does the boolean statement do?

Why are you comparing it to greater than or equal to 0?
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you read the API for calendar you would see that the compareTo() method returns 0 if the two calendar items are equal, returns a negative number if now comes before evening or a positive number if now comes after evening. So I take the result and check if the returned value is >= 0. If so, now is equal to or later than what I define evening to be, so it is evening now, otherwise it is before evening.

The way to use it would be in combination with my previous post (in pseudocode):
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!