Solved

change military time to Standard time

Posted on 2004-04-24
7
4,162 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
Comment Utility
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
Comment Utility
0
 

Author Comment

by:calvinklein1
Comment Utility
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 Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 92

Accepted Solution

by:
objects earned 125 total points
Comment Utility
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
Comment Utility
Thank you!!!
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
0
 
LVL 1

Expert Comment

by:alkonaut
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
copyEndy  challenge 15 55
count8 challlenge 13 84
Systems talking to each other 5 107
Problem to start Neon 20 49
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…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

771 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now