package utils;
import java.util.*;
import java.text.*;
import java.sql.Timestamp;
public class DateToTimestamp {
public static void main(String[] args) {
try {
String str_date = "11/12/2010";
DateFormat formatter;
Date date;
formatter = new SimpleDateFormat("dd/MM/yyyy",Locale.UK);
date = (Date) formatter.parse(str_date);
java.sql.Timestamp timeStampDate = new Timestamp(date.getTime());
System.out.println("Today 1 is " + timeStampDate);
str_date = "11/12/2010 10:12:03";
formatter = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss",Locale.UK);
date = (Date) formatter.parse(str_date);
timeStampDate = new Timestamp(date.getTime());
System.out.println("Today 2 is " + timeStampDate);
} catch (ParseException e) {
System.out.println("Exception :" + e);
}
}
}
/**
######### OUTPUT ###########
Today 1 is 2010-12-11 00:00:00.0
Today 2 is 2010-12-11 10:12:03.0
*/
Tag: Study Code Program Java
Sunday, December 19, 2010
Date To Timestamp
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment