Convert Formatted String to Timestamp Value

From Java Example Source Code

Jump to: navigation, search

Contents

[edit] Overview - Convert Formatted String to Timestamp Value

This Java example program demonstrates how to convert formatted string to Timestamp value.

[edit] Java Source Code

  • Package: example.datetimetimestamp
  • File: DateLabel2.java
package example.datetimetimestamp;
public class DateLabel2 {
    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:

1219929735601
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