问题
I am pulling data from an API, and one of the pieces of data I get is a date and time. The date and time is returned in a string format and I need to get that in to a Unix Timestamp for my mySQL database.
The String looks like: "2018-10-23 18:00:00"
Does anyone know how I would go about getting that from a String to a Unix Timestamp? Should I try using java.util.Date?
回答1:
Similar to this
Convert a date format in epoch
but change
SimpleDateFormat df = new SimpleDateFormat("MMM dd yyyy HH:mm:ss.SSS zzz");
to
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
来源:https://stackoverflow.com/questions/52956063/string-date-and-time-to-unix-timestamp-in-java