• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 251
  • Last Modified:

formatting a date

Good afternoon everyone, I have probably a real simple question but I am not very clear on how to do it. I need to format a date that is comming into my program as "200404271127" And I need take that date and make it into this format 04/27/2004. Any ideas? Thanks
0
D_basham
Asked:
D_basham
  • 5
1 Solution
 
Tommy BraasCommented:
Use java.text.SimpleDateFormat
0
 
Tommy BraasCommented:

String dateString = ....
SimpleDateFormat dfIn = new SimpleDateFormat("yyyyMMddHHmm");
Date myDate = dfIn.parseDate(dateString);
SimpleDateFormat dfOut = new SimpleDateFormat("MM/dd/yyyy");
String newFormattedString = dfOut.format(myDate);
0
 
Tommy BraasCommented:
Of course, if the format is fixed then the substring approach would work as well:
String dateString = ....
StringBuffer strbuf = new StringBuffer();
strbuf.append(dateString.substring(4, 6));
strbuf.append('/');
strbuf.append(dateString.substring(6, 8));
strbuf.append('/');
strbuf.append(dateString.substring(0, 4));
String newlyFormattedDateString = strbuf.toString();
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
objectsCommented:
> Date myDate = dfIn.parseDate(dateString);

that should be

Date myDate = dfIn.parse(dateString);
0
 
Tommy BraasCommented:
>> Date myDate = dfIn.parse(dateString);
of course....;-)
0
 
D_bashamAuthor Commented:
Thanks for the help the substring parsing is what I needed and it worked. Stick around I am doing a lot of java programming for work may come up with more questions. Thanks a lot. :)
0
 
Tommy BraasCommented:
=-)
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now