aspose file tools*
The moose likes Beginning Java and the fly likes One liner for getting tomorrows date in mm/dd/yyyy format. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "One liner for getting tomorrows date in mm/dd/yyyy format." Watch "One liner for getting tomorrows date in mm/dd/yyyy format." New topic
Author

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

Alan Parson
Greenhorn

Joined: Feb 20, 2006
Posts: 10
Can I get the tomorrows date in mm/dd/yyyy format in one line of Java?
Mike Noel
Ranch Hand

Joined: Dec 15, 2005
Posts: 108
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.


Mike Noel
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14428
    
  23

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:


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
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:


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: One liner for getting tomorrows date in mm/dd/yyyy format.