This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

date problem

 
Aanchal Tyagi
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
private String date = new SimpleDateFormat("dd-MM-yy", Locale.getDefault()).format(new java.util.Date();

is there any way to add n days in above variable

for example
private String date=22 aug 2006

if i add 7 days to it ,it becomes
date=29 aug 2006

is ther any way to convert string into date please help by giving example if possible.


thanks in advance.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> is there any way to add n days in above variable

create a new Date out of the current Date's milliseconds + n*(milliseconds in a day).
but this is a real 'hack'.

better to create a calendar object, add 7 days, then format calendar.getTime()
 
Brian Mozhdehi
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
conversion from String to Date and vice versa is done using the class SimpleDateFormat, which is in the java.text package. You can search on it in google and find Suns javadoc page which is an excellent reference on how to use it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic