我的Android应用程序中有一个微调器,并且onItemSelected()在进入活动时会自动触发其事件.
我该如何避免这种情况?
我有时间数据分为两个字符串 - 一个字符串表示日期,一个字符串表示时间.
我想计算差异.在Java中这样两次.
例如
差异将是13小时15分钟.
我一直在使用robotium来测试我的android应用程序.测试成功但我想知道有没有办法在单独的文件中查看测试结果.
我试图计算给定两次之间的差异,我发现它有一些问题.假设我们有时间值是"11:AM"和10:00 AM".我能够计算但是AM,PM有点混乱.提前感谢
我使用以下代码:
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class StringToDate {
public static String timeDiff(String time1, String time2) {
String Time = null;
int difference;
String a1 = time1.substring(6);
String a2 = time2.substring(6);
try {
// Define a date format the same as the expected input
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm a");
// Get time values of the date objects
long l1 = sdf.parse(time1).getTime();
long l2 = sdf.parse(time2).getTime();
difference = (int) (l2 - l1);
difference = (difference < …Run Code Online (Sandbox Code Playgroud)