• 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
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

how to add 30 days to current data?

 
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am trying to add 30 days to current date. But couldn't succeed.
Actually i want to display in result the date which is 30 day after current date? How that we can do without using Calender Object or any third party component?
Please reply.
Thank you.
Pras
 
Ranch Hand
Posts: 1249
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Satou kurinosuke:
Why can't you ? Did you try Calendar.add(int field, int amount) ?



Satou,

As he mentioned he cann't use Calendar..
 
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm also wondering why you do not want to use the Calendar classes?

If you do not want to use this you will have to make the calculations yourselves. This means however that you will have to take in account leapyears, days in month, ...

I don't see why this can not be done but it is code that exists allready in the java.util.Calendar class(es).
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

As he mentioned he cann't use Calendar..


Sorry, I read "with Calendar" I will delete my post
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I also wonder why you can't use Calendar - using Calendar is the simplest and clearest way to do this.

But OK, if you don't want to use Calendar for whatever reason, it's very simple to add 30 * 24 * 60 * 60 * 1000 milliseconds (which is 30 days) to the current date.

You don't have to do difficult things with leap years, number of days in a months etc. as Manuel suggests.
 
Ranch Hand
Posts: 257
Hibernate Firefox Browser Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Just for curiosity, want to know why you dont want to use Calendar?
 
Manuel Moons
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes Jesper, you are right. He can calculate the days by using the Date class. I supposed however that if he doesn't want to use the Calendar classes that he also does not want to use the Date class.

Maybe I supposed a little to much???
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!