• 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
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

Can't format String To Date

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Guys,
I have some problem's here.
I try to convert String dd/MM/yyyy to Date dd/MM/yyyy.
This is my source code :


But the ouput is:

dateThu Oct 01 00:00:00 ICT 2015


I'm tyring to convert with different source code, but the result is same.

Thanks in advance.
 
Ranch Hand
Posts: 46
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Leave your code as it is, then add this line before System.out

Then you can print this one
 
Irliyanti Rahmadhani Lubis
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Martin Bechtle wrote:Leave your code as it is, then add this line before System.out

Then you can print this one




So, it change to String. But I need Date in line 10, Martin.

 
Martin Bechtle
Ranch Hand
Posts: 46
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Allright... well a Date object has no format in Java. It only gets a format when it's transformed into a String or parsed from a String. So you have to find where in your code the date gets printed and use the code I gave you there.
 
Irliyanti Rahmadhani Lubis
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Martin Bechtle wrote:Allright... well a Date object has no format in Java. It only gets a format when it's transformed into a String or parsed from a String. So you have to find where in your code the date gets printed and use the code I gave you there.




I don't understand that flow.
So, you ask me to add :

in my code.

And then, I make it like:


I change your to my String .
but, because it's String, on the , it's need Date Type. I'm making it to
So, I add the
The result, it's Error.


Actually, I want to SELECT data by Date.
In the table of DB, the type Date is Date (MM/dd/yyyy).

and I use Native SQL in My Hibernate, like :



My Service source code, is:



and the format date is my Controller.

I'm not yet found to solved that.
 
Irliyanti Rahmadhani Lubis
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Martin Bechtle wrote:Allright... well a Date object has no format in Java. It only gets a format when it's transformed into a String or parsed from a String. So you have to find where in your code the date gets printed and use the code I gave you there.




Okay, I got it what you mean, Martin.
So you want me to convert that String To Date and to String again? so it can be like dd/MM/yyyy format.
Hem, I there's another way to make it still "Date". Because, I want Date.
 
reply
    Bookmark Topic Watch Topic
  • New Topic