-2

I want to transform a String that looks like an sql Timestamp into an actual Timestamp. How can I do that? My string looks like this.

    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    System.out.print("Please enter StartTime (YYYY-MM-DD HH:MM:SS): ");

    String StartTime = null;

    try {
        StartTime = reader.readLine();

    } catch (IOException e) {
        e.printStackTrace();
    } 

Then, I want to compare this timestamp, with a Timestamp from an sql database..Can I do something like that?

Thanks in advance!

MByD
  • 135,866
  • 28
  • 264
  • 277
Hory Hene
  • 31
  • 6

2 Answers2

0

Use the Timestamp.valueOf to convert it to a java.sql.Timestamp

shyam
  • 9,134
  • 4
  • 29
  • 44
0

You can simplay use the class SimpleDateFormat.According to documentation :

SimpleDateFormat is a concrete class for formatting and parsing dates in a locale-sensitive manner. It allows for formatting (date -> text), parsing (text -> date), and normalization.

abc
  • 75
  • 2
  • 9