【发布时间】:2015-02-16 11:06:22
【问题描述】:
我正在尝试从包含日期的字符串中获取毫秒数,但似乎我得到了错误的值。这是我试图解析的字符串:2015-03-01 00:00:00,
我这样做是为了解析它:
DateFormat dateFormat = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss");
Date inputDate = dateFormat.parse(data.get(position).getValidTo());
Log.d("--", inputDate.getDay() + " | " + inputDate.getMonth());
【问题讨论】:
-
你从中得到了什么?
-
你想要
yyyy-MM-dd HH:mm:ss。然后不要在Date上使用已弃用的方法......你只是在自找麻烦。 -
请包含日志文件。并记录 data.get(position).getValidTo() 的内容以检查字符串是否有效
-
@MichałSzydłowski 当我做
Log.d("--", inputDate.getDay() + " | " + inputDate.getMonth());我得到4 | 0 -
inputDate.getTime();它会以毫秒为单位给出时间。
标签: java android android-calendar android-date java-time