我正在尝试使用下面的代码将时间字符串转换为毫秒。因为我会将时间用作倒数计时器。
问题是时间来自数据库并且它是 varchar 类型。我试过这段代码,但它没有给我正确的输出。
String timeDuration = "10:00"; //for example only
SimpleDateFormat sdf = new SimpleDateFormat("mm:ss");
Date time = sdf.parse(timeDuration);
long millis = time.getTime(); //The output must be 600000
Run Code Online (Sandbox Code Playgroud)
我使用此代码得到错误的“毫秒”。
我正在使用 Android Studio。