形式に従って、日付と時刻の両方のタイムスタンプを見つけるにはどうすればよいですか:
Wed Oct 31 17:40:42 IST 2012
を使用しSimpleDateFormat
て日付を解析します
SimpleDateFormat parserSDF=new SimpleDateFormat("EEE MMM d HH:mm:ss zzz yyyy");
Calendar cal = Calendar.getInstance();
System.out.println(parserSDF.format(cal.getTime()));
として印刷されますWed Oct 31 18:28:55 IST 2012
使用SimpleDateFormat
:
String str_date = "Wed Oct 31 18:28:55 IST 2012";
// Here is your date as string
DateFormat formatter = new SimpleDateFormat("EEE MMM d HH:mm:ss zzz yyyy");
Date date = (Date) formatter.parse(str_date);
Timestamp timeStampDate = new Timestamp(date.getTime());
// Here is your date as timestamp