My blog has moved! Redirecting...

You should be automatically redirected. If not, visit http://mindsiview.wordpress.com/ and update your bookmarks.

Tuesday, June 15, 2004

Java Quick Tip of the Day: Getting the Date in YYYYMMDD Format

There are times when you need to return a date as string in YYYYMMDD format. Here's a simple way to do it:
    import java.text.*;
    ...
    ...
    ...
    SimpleDateFormat sf = new SimpleDateFormat("yyyyMMdd");
    java.util.Date date = java.util.Calendar.getInstance().getTime();
    System.out.println(sf.format(date));

3 comments:

Anonymous said...

Thanks for the tip!

Anonymous said...

Could you please get a Date with a Date type (not in String type)in YYYYMMDD format?

Rick said...

Tim,

Are you asking for an example or are you wanting me to change my example? Although I didn't explain it in my blog, the example I showed was based on a need that one of my staff had. If you'd like, I can post other examples of using/manipulating Date and/or Calendar objects.

Technorati search