How to convert Formatted date (yyyy-MM-dd) to Unix time in Java?
I want to declare a date using
Date birthday = new Date(y_birthday, m_birthday, d_birthday);
but this constructor has been deprecated, so I got to use the other constructor which uses Unix timestamp
Use a calendar object if you want more control of the date object
The hours, minutes, seconds etc of the current time will be set though so you may want to set those to 0 (manually per field)
If you're using Java 7 then I think there's some much nicer stuff you can use for handling dates
So, you have the date as a string in the format
yyyy-MM-dd
? Use ajava.text.SimpleDateFormat
to parse it into ajava.util.Date
object:edit If you need a
java.sql.Date
, then you can easily convert yourjava.util.Date
to ajava.sql.Date
: