The following code generates timestamp using java code in two ways.
import java.io.*;
import java.util.*;
import java.text.*;
import java.sql.Timestamp;
public class TimeStamp {
public static void main(String [] args){
try{
java.util.Date today=new java.util.Date();
java.sql.Timestamp todayTimeStamp =new java.sql.Timestamp(today.getTime());
java.sql.Timestamp now=new java.sql.Timestamp( System.currentTimeMillis() );
DateFormat df = new SimpleDateFormat ("yyMMddHHmmssSS");
df.setLenient(false);
String timeStamp=df.format(today);
//Date date1=df.parse("10/06/2010");
//Date date2=df.parse(dateSt2);
System.out.println("Timestamp SQL "+ todayTimeStamp);
System.out.println("Timestamp SQL2 "+ now);
System.out.println("Timestamp Util "+ timeStamp);
}
catch(Exception e){
System.out.println("Error" + e);
}
}
}
0 comments:
Post a Comment