Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

One liner for getting tomorrows date in mm/dd/yyyy format.

 
Alan Parson
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can I get the tomorrows date in mm/dd/yyyy format in one line of Java?
 
Mike Noel
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here ya go.

System.out.println((new SimpleDateFormat("MM/dd/yyyy")).format(new Date(((new Date()).getTime() + 86400000))));

It's dog ugly and there might be a better one-line solution but this is the best I could think of.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15203
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd like to slightly modify Mike's version, although it's still ugly:

Is there a special reason why it has to be one line, or is that "just for fun"? A cleaner way to do it would be this, but it's three lines:
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jesper Young:
Is there a special reason why it has to be one line, or is that "just for fun"? A cleaner way to do it would be this, but it's three lines:
[/QB]


You could also make that a one-liner:



:roll:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic