• 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:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

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: 1935
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: 1935
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
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.

 
I love a woman who dresses in stainless steel ... and carries tiny ads:
global solutions you can do at home or in your backyard
https://www.kickstarter.com/projects/paulwheaton/better-world-boo
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!