字符串(日期和时间)到 Java 中的 Unix 时间戳 [英] String (Date and Time) to Unix Timestamp in Java
本文介绍了字符串(日期和时间)到 Java 中的 Unix 时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从 API 中提取数据,我得到的数据之一是日期和时间.日期和时间以字符串格式返回,我需要将其输入到 mySQL 数据库的 Unix 时间戳中.
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.
字符串看起来像:2018-10-23 18:00:00"
The String looks like: "2018-10-23 18:00:00"
有谁知道我将如何将它从字符串转换为 Unix 时间戳?我应该尝试使用 java.util.Date 吗?
Does anyone know how I would go about getting that from a String to a Unix Timestamp? Should I try using java.util.Date?
推荐答案
与此类似
但要改变
SimpleDateFormat df = new SimpleDateFormat("MMM dd yyyy HH:mm:ss.SSS zzz");
到
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
这篇关于字符串(日期和时间)到 Java 中的 Unix 时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文