package com.example.calculatecurrenttime;
import java.util.Calendar;
import java.util.TimeZone;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Calendar c = Calendar.getInstance();
TimeZone timeZone = c.getTimeZone();
long totalMilliseconds = System.currentTimeMillis() + timeZone.getRawOffset();
long totalSeconds = totalMilliseconds / 1000;
long currentSenconds = totalSeconds % 60;
long totalMinutes = totalSeconds / 60;
long currentMinutes = totalMinutes % 60;
long totalHours = totalMinutes / 60;
long currentHours = totalHours % 24;
Log.d("xiaoxi", "current time is :" + currentHours + ":" + currentMinutes + ":" + currentSenconds);
}
}
Android日期转换参考