Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to get yesterday's business date

 
nancy andrew
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am writing a program which gets todays date and yesterday's date. The dates should be business dates. If today is Tuesday then it should furnish yesterday's date which was a Monday. But if today is Monday then it should furnish yesterday's date which was a friday. How to write this program in java. Also the dates which i want should be in Eastern standard time. I dont want GMT. Please help me.

Regards,
Nancy
 
Lester Burnham
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like: create a Calendar object, subtract a day from it, check if it's on a weekend and if so, subtract 1 or 2 days from it depending on whether it's a Saturday or Sunday. The Calendar class has all the methods you'd need for this, and it can handle timezones.

Would you need to consider official holidays as "non-business days"?
 
Jacob Anawalt
Ranch Hand
Posts: 64
Linux Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want something more robust, and especially if you need holidays, consider a library like Objectlab kit. I've been happy with it and Joda.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic