ya i looked in to this class too; But i am not able to get any clear idea about how should i proceed.
Please help me out.
You use the SimpleDateFormat class to take a String and convert it into a Date object. The Date object holds time information too, not just date information. Once you have your Date object, you can use the Calendar class to extract the time information out of it.
SCJP 6 || SCWCD 5
vijay shanker
Ranch Hand
Joined: Oct 26, 2007
Posts: 88
posted
0
There is something missing in my requirement and your suggestions.
1. i am not aware of what format user enters to input time values. It can be like i said 9:30PM or 9:30 PM or 9:30 pm or 9:30pm or 9:30p.
2. i see SimpleDateFormat supports to fetch time formats from any input text. but not able to identify how to set variable format like i have given above.
3. Throwing exception is not my motive. I want to perceive what any user has given in the input. and i want it to be correctively perceived,
vijay shanker wrote:i am not aware of what format user enters to input time values.
As with any input you get from the user, you should (1) clean it so that it matches the format you're looking for, (2) force the user to input it in a specific way, or (3) use a combination of both. Maybe something like this:
Campbell Ritchie wrote:Since aM is not a recognised abbreviation (it should always be am not AM) you should be throwing an Exception for erroneous input.
I have not seen a reference that agrees with this. That must be unique to the UK (or is it U.K. ). http://en.wikipedia.org/wiki/12-hour_clock I bet you also put your curly braces in the wrong place don't you.
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32830
4
posted
0
I've never seen capitals for am or pm. But the 12-hours clock is now largely restricted to informal uses.
Javaranch uses PM in the posting times at the top of each individual message.
I think there may be a bug though because it doesn't change to AM when I post a message in the mornings.
Edit - just noticed it only appears in other people's posts - not in my posts.
That's strange. The PM didn't appear in my post when I viewed the thread straight after posting, but it does appear now.
Edit - ignore that. i wasn't logged in when I saw the PM in my post. D'oh.
Anyway, enough of the serious stuff. Which of my posts do you see AM in ?
Edit2 - apologies to vijay for hijacking his post. Probably should stop this now as I don't think he has got an answer yet.