• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

parse string to time

 
Greenhorn
Posts: 24
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi to everyone!

i have a problem about parsing string to time.
Here is my samplecode:

String time = request.getParameter("time");
Time tm = Time.parse(time);

but it goes error...

i tried another code like this...

String time = request.getParameter("time");
Time tm = Time.valueOf(time);

but it goes error too...

i tried also this code...

String time = request.getParameter("time");
DateFormat sdf = new SimpleDateFormat("hh:mm");
Time tm = (Time) sdf.parse(time);

it goes error too...
it says: Cannot parse Date to Time

my datatype of 'time' in database is time without time zone
what is wrong?

please help me.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should be using java.util.Date or java.util.Calendar not java.sql.Time.
 
max soyosa
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ahm, i have used java.util.date but it still goes error.
what should i do?

please give me a sample code...

thanks.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

max soyosa wrote:my datatype of 'time' in database is time without time zone



And is that why you are asking this question? If so why is it a question about strings? Why don't you just get a Time object from the database?
 
max soyosa
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ahm, its just a clarification why i need to parse a string to time.
 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

max soyosa wrote:ahm, i have used java.util.date but it still goes error.
what should i do?

please give me a sample code...

thanks.

Just look at the (Simple)DateFormat class and you will be able to come up with something on your own.
 
reply
    Bookmark Topic Watch Topic
  • New Topic