• 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

string to timestamp

 
Ranch Hand
Posts: 37
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there,

1)I have a string of this type of format: dd MMM yyyy.
2)I want to end up with a Timestamp of this format: yyyy-mm-dd hh:mm:ss

I've gone back and forth between string, date, formatter, timestamp and I keep getting exceptions of all kinds, can anyone post a code that would begin with and end with the above formats in those type of objects?

Thanks in advance
 
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
1. Create a SimpleDateFormat object which matches that format.

2. Use it to parse a String to a Date.

3. Convert that Date to a long value using a method whose name I think might be getTime().

4. Pass that long value to a Timestamp constructor.

By the way it doesn't make sense to require that a Timestamp should have any kind of format. It's just a time stamp, it doesn't have a format. If you need to produce a String representation of the Timestamp using some particular format then:

1. Create a SimpleDateFormat object which matches that format.

2. Use it to format the Timestamp to a String.

 
Ranch Hand
Posts: 48
Eclipse IDE Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Klament J. Kruoghst wrote:
2)I want to end up with a Timestamp of this format: yyyy-mm-dd hh:mm:ss



In the above line the month field 'mm' should be 'MM'. Coming to code part, hope this will help.

 
reply
    Bookmark Topic Watch Topic
  • New Topic