Solved

change military time to Standard time

Posted on 2004-04-24
7
4,223 Views
Last Modified: 2008-02-01
I have a database returning a time to me, but it's in military time.   Like this:
15:00:00
15:15:00
15:30:00
15:45:00
16:00:00
16:15:00

What can I call that will format this time to the regular standard time???  Like this:
3:00 PM
3:15 PM
3:30 PM
4:00 PM
4:15 PM

I was trying to use this:
SimpleDateFormat sdf = new SimpleDateFormat("hh:mm");
sdf.format(time);

but it only excepts a Date and no time.    Can anyone help me?   Thanks
0
Comment
Question by:calvinklein1
7 Comments
 
LVL 92

Expert Comment

by:objects
ID: 10910039
SimpleDateFormat standard= new SimpleDateFormat("hh:mm");
SimpleDateFormat military = new SimpleDateFormat("HH:mm");
String regular = standard.format(military.parse(fromdb));

0
 
LVL 7

Expert Comment

by:maheshexp
ID: 10910057
0
 

Author Comment

by:calvinklein1
ID: 10910109
Thank you object.   but i'm still get an error when trying to parse the object from the database (or in the case the vector that was created from the database).  This is the error:

unhandled exception: java.text.ParseException
and it's for this line code from below:
regular = standard.format(military.parse(y.get(1).toString());

y.get(1)  is an object from the vector that's the way it was put in.   Do I need to cast it to a string or something to make this work???   Here's the method i'm using:

    public ArrayList getTimeSlotTime(){
        ArrayList timeSlotTime = new ArrayList(this.size);
        SimpleDateFormat standard= new SimpleDateFormat("hh:mm");
        SimpleDateFormat military = new SimpleDateFormat("HH:mm");
        String regular;
               
        Vector y;
        for(int i = 0;i < size;i++){
            y = (Vector)slotIdVector.elementAt(i);
            regular = standard.format(military.parse(y.get(1).toString());
            timeSlotTime.add(i,regular);
        }
        return timeSlotTime;
    }
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 92

Accepted Solution

by:
objects earned 125 total points
ID: 10910117
you just need to handle the exception:

        for(int i = 0;i < size;i++){
            y = (Vector)slotIdVector.elementAt(i);
            try {
               regular = standard.format(military.parse(y.get(1).toString());
            } catch (ParseException ex) {
               // parse error, handle as appropriate
               ex.printStackTrace();
               regular = "??:??";
            }
            timeSlotTime.add(i,regular);
        }
0
 

Author Comment

by:calvinklein1
ID: 10910146
Thank you!!!
0
 
LVL 92

Expert Comment

by:objects
ID: 10910164
0
 
LVL 1

Expert Comment

by:alkonaut
ID: 10948853
Actually, "the regular standard time" as you say is just a queer time format used in the US, while "military time" (24h) is the norm. (Much like the imperial system of measurement).

Come on, catch up =)
0

Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question