• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Time Class

 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Hibernate Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
but how do I differentiate the afternoon from evening though?

 
Steve Luke
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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):
 
reply
    Bookmark Topic Watch Topic
  • New Topic