How to Convert java.sql.Timestamp to java.lang.String

From Java Example Source Code

Jump to: navigation, search

Contents

[edit] Overview - How to Convert java.sql.Timestamp to java.lang.String

This Java example program demonstrates how to convert Convert java.sql.Timestamp to java.lang.String.

[edit] Java Source Code

  • Package: datetimetimestamp
  • File: DateLabel.java
package example.datetimetimestamp;
 
public class DateLabel {
    public static void main(String[] args) {
	java.util.Date today = new java.util.Date();
	java.sql.Timestamp ts1 = new java.sql.Timestamp(today.getTime());
	java.sql.Timestamp ts2 = java.sql.Timestamp.valueOf("2005-04-06 09:01:10");
 
	long tsTime1 = ts1.getTime();
	long tsTime2 = ts2.getTime();
 
	System.out.println(tsTime1);
	System.out.println(tsTime2);
    }
}

[edit] What Result You Can Get

Run the program, you will get:

1219926306129
1112803270000

[edit] Required External Libraries and/or Files for this Java Example

Need nothing.


[edit] How to Run this Java Example Program

We recommend running this Java example program with Eclipse.

For assistance in working with Eclipse, please see How to Run Java Program with Eclipse.

It's fairly easy.



[edit] Question & Answer

Any question?

Click edit and post your question or answer here.


Personal tools