Reputation: 6081
so I get a String that is a date. Example: 2012-10-22 10:00:00
Now I want the Unix Timestamp of this date. So first I have to convert it into a SimpleDateFormat
String metaDate = (metaDateList.item(0)).getNodeValue(); //2012-10-22 10:00:00
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd HH:mm:ss");
Date nonUnixDate;
nonUnixDate = sdf.parse(metaDate);
System.out.println ( nonUnixDate.getTime() );`
The problem I'm encountering is that the unix timestamp is 1358675994000
which is Thu, 23 Sep 45024 14:20:00 GMT
. Seems like I have an error somewhere, but where is it?
Upvotes: 0
Views: 403
Reputation: 326
You are using the wrong format, you should use MM
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Upvotes: 4
Reputation: 308141
The unix timestamp is defined in seconds.
Date.getTime()
returns milliseconds.
So your result will be off by a factor of 1000.
Upvotes: 4