[java] Converting Milliseconds to Minutes and Seconds?

package com.v3mobi.userpersistdatetime;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.Toast;

import java.util.Date;
import java.util.concurrent.TimeUnit;

public class UserActivity extends AppCompatActivity {

    Date startDate;
    Date endDate;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user);
        startDate = java.util.Calendar.getInstance().getTime(); //set your start time
    }

    @Override
    protected void onStop() {
        super.onStop();
        endDate = java.util.Calendar.getInstance().getTime(); // set  your end time

        chekUserPersistence();

    }

    private void chekUserPersistence()
    {
        long duration = endDate.getTime() - startDate.getTime();
//        long duration = 301000;

        long diffInMinutes = TimeUnit.MILLISECONDS.toMinutes(duration);         // minutes ok
        long secs = (duration/1000) % 60;         // minutes ok


        Toast.makeText(UserActivity.this, "Diff  "
                +  diffInMinutes + " : "+ secs , Toast.LENGTH_SHORT).show();

        System.out.println("Diff  " + diffInMinutes +" : "+ secs );

        Log.e("keshav","diffInMinutes -->" +diffInMinutes);
        Log.e("keshav","secs -->" +secs);
        finish();
    }
}

Examples related to java

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How much should a function trust another function How to implement a simple scenario the OO way Two constructors How do I get some variable from another class in Java? this in equals method How to split a string in two and store it in a field How to do perspective fixing? String index out of range: 4 My eclipse won't open, i download the bundle pack it keeps saying error log

Examples related to time

Date to milliseconds and back to date in Swift How to manage Angular2 "expression has changed after it was checked" exception when a component property depends on current datetime how to sort pandas dataframe from one column Convert time.Time to string How to get current time in python and break up into year, month, day, hour, minute? Xcode swift am/pm time to 24 hour format How to add/subtract time (hours, minutes, etc.) from a Pandas DataFrame.Index whos objects are of type datetime.time? What does this format means T00:00:00.000Z? How can I parse / create a date time stamp formatted with fractional seconds UTC timezone (ISO 8601, RFC 3339) in Swift? Extract time from moment js object

Examples related to type-conversion

How can I convert a char to int in Java? pandas dataframe convert column type to string or categorical How to convert an Object {} to an Array [] of key-value pairs in JavaScript convert string to number node.js Ruby: How to convert a string to boolean Convert bytes to int? Convert dataframe column to 1 or 0 for "true"/"false" values and assign to dataframe SQL Server: Error converting data type nvarchar to numeric How do I convert a Python 3 byte-string variable into a regular string? Leading zeros for Int in Swift

Examples related to stopwatch

Converting Milliseconds to Minutes and Seconds? Calculate the execution time of a method Is there a stopwatch in Java?

Examples related to watch

What is the Angular equivalent to an AngularJS $watch? AngularJS $watch window resize inside directive Converting Milliseconds to Minutes and Seconds? AngularJS : Clear $watch How to deep watch an array in angularjs? AngularJS : How to watch service variables? OS X Bash, 'watch' command Is there a command like "watch" or "inotifywait" on the Mac? Watching variables in SSIS during debug How do I watch a file for changes?