String (Date and Time) to Unix Timestamp in Java [duplicate]

淺唱寂寞╮ 提交于 2021-01-29 05:30:34

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!