calvinklein1
asked on
change military time to Standard time
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
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
http://java.sun.com/j2se/1.3/docs/api/java/text/DateFormat.html, u have lot of options here
ASKER
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.p arse(y.get (1).toStri ng());
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.eleme ntAt(i);
regular = standard.format(military.p arse(y.get (1).toStri ng());
timeSlotTime.add(i,regular );
}
return timeSlotTime;
}
unhandled exception: java.text.ParseException
and it's for this line code from below:
regular = standard.format(military.p
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.eleme
regular = standard.format(military.p
timeSlotTime.add(i,regular
}
return timeSlotTime;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you!!!
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 =)
Come on, catch up =)
SimpleDateFormat military = new SimpleDateFormat("HH:mm");
String regular = standard.format(military.p