【发布时间】:2012-10-31 12:52:57
【问题描述】:
如何根据格式找到日期和时间的时间戳:
Wed Oct 31 17:40:42 IST 2012
【问题讨论】:
如何根据格式找到日期和时间的时间戳:
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
【讨论】: