[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

change military time to Standard time

Posted on 2004-04-24
7
Medium Priority
?
4,545 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 92

Accepted Solution

by:
objects earned 500 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

Technology Partners: 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!

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
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 one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Suggested Courses
Course of the Month18 days, 16 hours left to enroll

834 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