DateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = new Date(System.currentTimeMillis());
String logindate1 = simpleDateFormat.format(date);
//存入时间
MySp.putString(LoginActivity.this, "logindate1", logindate1);
2.计算时间差
private void TimeCompare(String date1, String date2) {
long nd = 1000 * 24 * 60 * 60;// 一天的毫秒数
long nh = 1000 * 60 * 60;// 一小时的毫秒数
long nm = 1000 * 60;// 一分钟的毫秒数
long ns = 1000;// 一秒钟的毫秒数
//格式化时间
DateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// String date1 = "2015-01-25 09:12:09";
// String date2 = "2015-01-29 09:12:11";
try {
Date beginTime = simpleDateFormat.parse(date1);
Date endTime = simpleDateFormat.parse(date2);