• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

can java.sql.Date in different Date pattern ?

 
Ranch Hand
Posts: 472
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi, good day, i just wan to ask whether we can have java.sql.Date in date pattern like 12/25/2005 rather just 2005-12-25 ? thank you
 
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
java.sql.Date like its superclass java.util.Date is basically a long timestamp: it's about the value, not the formatting. If you want to produce string representation of a date formatted in a certain way, use SimpleDateFormat.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Date objects (whether it's java.util.Date or java.sql.Date) do not have a format. When you convert a Date object to a string by calling toString() on it, the date is formatted with a certain default format.

If you want to have your Date object formatted differently, use java.text.SimpleDateFormat to format it. Because java.sql.Date is a subclass of java.util.Date, you can pass java.sql.Date to the SimpleDateFormatter without converting anything. Example:
 
She's brilliant. She can see what can be and is not limited to what is. And she knows this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic