This week's book giveaway is in the Artificial Intelligence forum.
We're giving away four copies of Pragmatic AI and have Noah Gift on-line!
See this thread for details.
Win a copy of Pragmatic AI this week in the Artificial Intelligence forum!
  • 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

date  RSS feed

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how do i get the dates of the days seven days before the actual date?e.g.like today is 4th march,i would like to get 3rd march,2nd march,1st march,31st january,30th january,29th january,28th january.using java code
 
Rancher
Posts: 1878
15
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is one of the probable solutions, there might be better approaches too.

 
Rancher
Posts: 425
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

daisy kagia wrote:how do i get the dates of the days seven days before the actual date?e.g.like today is 4th march,i would like to get 3rd march,2nd march,1st march,31st january,30th january,29th january,28th january.using java code


What do you mean by "the actual date"? If it's the current date, one of the ways to get that using System.currentTimeMillis(). You can also make use of the java.util.Calender class.
 
Pushkar Choudhary
Rancher
Posts: 425
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Swastik,
We do not encourage giving ready made solutions. DontBeACodeMill.
 
Swastik Dey
Rancher
Posts: 1878
15
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My apologies for the same.
 
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nothing UI related here. Moving thread.
 
Java Cowboy
Sheriff
Posts: 16084
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Swastik, your solution has a bug: it isn't daylight savings proof. A day does not always have 24 hours; when switching from winter time to summer time it's 23 hours and when switching from summer time to winter time it's 25 hours.

It's better to use class Calendar's date arithmetic methods, which take daylight savings into account. And you can use SimpleDateFormat to format dates, which is more convenient than doing it yourself with a StringBuffer.

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!