File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Date format reversing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Date format reversing" Watch "Date format reversing" New topic

Date format reversing

JeffreyAaron Smith

Joined: Jan 26, 2013
Posts: 4
I've been working on a pair of programs (driver and driven) that will accept input in the form of numbers a slash mark and numbers, which represent the month and day. The program error checks the input for valid numbers and then prints a line with the numbers as entered (mm/dd) and with the month spelled out (Month dd). Unfortunately, my code is somehow reversing the value for the date (i.e. 02/05=May 2).

I'm sure this is something simple I'm overlooking, but I've been scouring this code all day and can't find it. Any help would be greatly appreciated.

The driver:

And the driven class:

Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63867

First of all, it's not the best idea to name your own classes the same as Java classes. Leave "Date" alone.

And, why are you writing all this code when the DateFormat and Calendar classes already have it all solved for you?

[Asking smart questions] [About Bear] [Books by Bear]
JeffreyAaron Smith

Joined: Jan 26, 2013
Posts: 4
Because this is a project for a class with very specific requirements. For instance the driven class portion of the program must be named, "" and the driver named "". It also must include a Date constructor that receives a string called dateStr. It must error check the input using try/catch.

Unfortunately now I've been error checking, rewriting, adding, deleting for so long now, I'm not sure where I'm at...looking over the code, I suspect I have complicated it more than it needs to be.

I'm sorry to be asking, but can you help look through my code and streamline/debug?
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

You expect the input format to be mm/dd - but this is not what you expect in your Date code.

You start with finding the date delimiter '/', then you try to find the month, but is is the day you select (spot + 2) - and then you try to find the day, but also here you select the wrong one, you select the month (spot -1)

Regards, Rene Larsen
Dropbox Invite
I agree. Here's the link:
subject: Date format reversing
It's not a secret anymore!