Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

SimpleDateformat

 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I m trying to get timestamp in this format

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.fffffffff");

but its giving Exception in thread "main" java.lang.IllegalArgumentException: Illegal pattern character 'f'

any help

Actually i need to format this " 9/7/2010 0:00" to oracle timestamp format i.e yyyy-MM-dd HH:mm:ss.fffffffff .. how can i achieve this ?

thanks
 
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

divya kundapur wrote:
I m trying to get timestamp in this format

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.fffffffff");

but its giving Exception in thread "main" java.lang.IllegalArgumentException: Illegal pattern character 'f'

any help



Did you have a look at the characters allowed for the format? You can find that in the API documentation for SimpleDateFormat class. 'f' isn't a valid symbol there.
 
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, I don't see 'f' listed as a valid format character at http://download.oracle.com/javase/1.4.2/docs/api/java/text/SimpleDateFormat.html. What are you trying to have show up in that field? Milliseconds would be an 'S'...

rc
 
Sheriff
Posts: 22684
128
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

divya kundapur wrote:Actually i need to format this " 9/7/2010 0:00" to oracle timestamp format i.e yyyy-MM-dd HH:mm:ss.fffffffff .. how can i achieve this ?


If you have problems when inserting / updating records with Oracle I suggest you use PreparedStatement instead. You can then simply use its setTimestamp method. Converting that date into a java.util.Date object should be simple; you can then create a Timestamp object using "new Timestamp(data.getTime())".
 
Ralph Cook
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The characters after the seconds value in an Oracle time are "nanoseconds"; java.util.time only stores times to millisecond precision, so there is no date formatter value for revealing nanoseconds from it.

See http://download.oracle.com/javase/1.4.2/docs/api/java/sql/Timestamp.html for a timestamp object that does have nanosecond values; it doesn't help you in this particular formatting example, but explains the difference between java times and sql times. Perhaps you can do what you want by storing times in a Timestamp object, then formatting by extracting the nanoseconds value separately as an int and formatting that. You can use SimpleDateFormat to get the time through the seconds value, then format the nanoseconds separately.

One more tip: on this forum, if you edit a post, the folks 'watching' that thread don't get notified. You edited your original post instead of replying to the post, so I didn't know you had put up more information until someone else replied to the post. Replying is more likely to get someone who replied before to do it again.

rc
 
Mohamed Sanaulla
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ralph Cook wrote:
One more tip: on this forum, if you edit a post, the folks 'watching' that thread don't get notified. You edited your original post instead of replying to the post, so I didn't know you had put up more information until someone else replied to the post. Replying is more likely to get someone who replied before to do it again.

rc



And I realized that the OP had edited the post only after reading this. And was till now thinking that I gave a wrong reply.
 
divya kundapur
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Thank you all for your help ,, i have finally got what i wanted and with all your guidance. 'f' is definitely not allowed in simpledateformat i went n read the api's after you guyz pointed that out.
 
A teeny tiny vulgar attempt to get you to buy our stuff
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic