Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Time datatype in Java?

  Asked By: Darcy    Date: May 21    Category: Java    Views: 3277
  

i need to create drop downs for times user can choose from (9:AM,
9:00PM, etc).
1. should i add a drop down list of Time types? if so... what type is
this? I just see Date, Calendar and Tomezones to use in those
calendars.

2. i would like to be able to do this
time= dropdown1.getchosen(); //whatever method returns type selected
then do
if(time=9:00AM)
do this;
3.
time1=dropdown1.getchosen();
time2=dropdown2.getchosen();
time1-time2= x hours?. (just return the number of hours(integer) not
an advanced type)


thanx if anyone can provide an API to refer to, or actual code, or
better yet post code to answer each one of those questions :) (option
1 is good enoguh for me).

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Adalia Fischer     Answered On: May 21

You can use the date  object for times as well. You just have to format the
output of the Date object so that it prints what you want in the drop  down.
Take a look at java.text.SimpleDateFormat for how to do your formatting. If the
Date object gives you problems, set the date to today's date or something and
then set whatever time  you want. The date will be ignored anyways.

 
Didn't find what you were looking for? Find more on Time datatype in Java? Or get search suggestion and latest updates.




Tagged: