simpledateformat to currenttimemillis-like format

时间:2011-10-12 17:19:42

标签: simpledateformat

有没有办法将使用 SimpleDateFormat 格式化的日期恢复为长期等效项(例如 System.currentTimeMillis())?

2 个答案:

答案 0 :(得分:1)

DateFormat format = new SimpleDateFormat("yyyy-MM-dd");

Date date = format.parse(VALUE).getTime();

我能想到的最简单的方式。

答案 1 :(得分:1)

您可以使用SimpleDateFormat.parse()获取Date个对象,然后在该Date个对象上调用getTime()

这将为您提供自1970年1月1日00:00:00 UTC(与System.currentTimeMillis()相同)后的毫秒数。