Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid - Compare Time String to Current Time Subtract Difference and Convert To MilliSeconds
    primarykey
    data
    text
    <p>I'm a bit new to Java/Android development and I need to compare two times. One of the time values is stored in a string and the other is the current to the system time (long) - how can I find out the difference between the two times in milliseconds and store it as a number? </p> <p>EDIT:</p> <p>Attempt # 1 (In Response to Lazy Ninja)</p> <pre><code>public class Rules extends Activity { private String password; private PendingIntent mPendingIntent; String TIMELIMIT = "10"; TextView textSsid, textSpeed, textRssi, Time; private static final int NOTIFY_ME_ID = 1337; private int count = 0; private NotificationManager notifyMgr = null; public Handler mHandler = new Handler(); public long mStartRX = 0; public long mStartTX = 0; public long txBytes; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.rules); String NDEF_PREF = "prefs"; SharedPreferences prefs = getSharedPreferences(NDEF_PREF, Context.MODE_PRIVATE); String name = prefs.getString("name", ""); String code = prefs.getString("corename", ""); String time = prefs.getString("time", ""); String ssid = prefs.getString("restricted", ""); Time = (TextView) findViewById(R.id.Time); Time.setText(time); String dtStart = "09:27:37"; SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss"); try { Date date = format.parse(time); } catch (ParseException e) { e.printStackTrace(); } Long convertedLong = date.getTimeInMillis(); long currentTimeLong = System.currentTimeMillis(); long difference = currentTimeLong - convertedLong; String strDiff = String.valueOf(difference); </code></pre> <p>PROBLEMS:</p> <p>date cannot be resolved Rules.java Java Problem</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload