Link to home
Start Free TrialLog in
Avatar of atxman
atxman

asked on

Format today's date in YYYYMMDD format

I am trying to format today's date to YYYYMMDD format by:
String today = new SimpleDateFormat("YYYYMMDD").parse(DateFormat.getDateInstance(DateFormat.MEDIUM).format(Calendar.getInstance().getTime())).toString();

However, what I am getting is the following error:
java.text.ParseException: Unparseable date: "Sep 28, 2015"

I am needing 20150928. Anyone know how to accomplish this?

Thanks
Avatar of CPColin
CPColin
Flag of United States of America image

Your format string is a little off. Check the Javadocs and try again. Your exception is happening because you're calling the parse() method. You don't need that, since you're formatting the date, not parsing it. Take it out and fix the format string and things should work better.
ASKER CERTIFIED SOLUTION
Avatar of Jim Cakalic
Jim Cakalic
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of atxman
atxman

ASKER

thanks for the insight. very helpful