• 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

show the date on the beginning of each day

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need to write some code that will show the current date at the
beginning of each day. The date should be shown exactly once when the
date changes from one day to the other.Please anyone help me.
 
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So you can have an endless loop, sleeping for a second (minute, whatever precision is needed), then get the date, compare it with previous, and react in some way, if it differs.
Where is the problem?
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See if the javax.swing.Timer helps you. You can schedule something for a future time and it will sleep until the time and then do the thing. If this is your only scheduled event it might be overkill. You might start a thread that does something like this in a forever loop:

No guarantees anything there is spelled right or easy to do but hope it gives you some inspiration.
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Assuming you have a process running continuously, you can start a thread that is responsible for showing the current date at the beginning of each day. You can then calculate the length of time before the beginning of the next day. You can then use Thread.sleep to sleep until it is time to show the display. That way, you don't use a lot of system resources waiting and checking.
Check out Calendar, Runnable (and Thread).
Good Luck
Don
 
I found some pretty shells, some sea glass and this lovely tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic