你好,我是android的新手,所以我想知道如何获取android中的时间间隔所以请帮我找到这个程序的时间间隔?我的老师说时间戳减去一次到另一个时间?去做吧?
public class MainActivity extends Activity {
private Button myLocation;
private TextView myAddress;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myLocation = (Button) findViewById(R.id.location);
myAddress = (TextView) findViewById(R.id.address);
myLocation.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getMyLocationAddress();
}
});
}
public void getMyLocationAddress() {
Geocoder geocoder= new Geocoder(this, Locale.ENGLISH);
try {
// Place your latitude and longitude
List<Address> addresses = geocoder.getFromLocation(28.437582, 76.995242, 1);
if (addresses != null) {
Address fetchedAddress = addresses.get(0);
StringBuilder strAddress = new StringBuilder();
for (int i = 0; i < fetchedAddress.getMaxAddressLineIndex(); i++) {
strAddress.append(fetchedAddress.getAddressLine(i)).append("\n");
}
myAddress.setText("I am at: " + strAddress.toString());
} else
myAddress.setText("No location found..!");
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(),"Could not get a address..!",Toast.LENGTH_LONG).show();
}
}
}
答案 0 :(得分:0)
目前还不清楚你在问什么,但是你可以得到当前的时间(从1970年开始):
long time= System.currentTimeMillis();
如果获取当前时间并执行您选择的操作并与保存的实例进行比较:
long start = long time= System.currentTimeMillis();
//Do method calls
long totalTimeSinceStart = System.currentTimeMillis() - start;