本篇文章主要介绍了"android 获取时间的工具类",主要涉及到Exception方面的内容,对于Android开发感兴趣的同学可以参考一下:
public SimpleDateFormat dateSimple = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")...
public SimpleDateFormat dateSimple = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
public SimpleDateFormat dateSimple2 = new SimpleDateFormat("yyyy年MM月dd日 E");
public SimpleDateFormat dateSimple3 = new SimpleDateFormat("yyyy-MM-dd");
/**
* 返回系统当前时间 :xxxx年xx月xx日 hh:mm:ss
* @return
*/
public String getNowTime() {
try {
return dateSimple.format(new Date())+"";
} catch (Exception e) {
Log.e(this, " getNowTime", e);
return null;
}
}
/**
* 返回系统当前时间 :xxxx年xx月xx日
* @return
*/
public String getNowTime2() {
try {
return dateSimple3.format(new Date());
} catch (Exception e) {
return "";
}
}
/**
* 返回系统当前时间 :xxxx年xx月xx日
* @return
*/
public String getNowDate() {
try {
return dateSimple3.format(new Date());
} catch (Exception e) {
return null;
}
}
/**
* 返回系统当前时间:xxxx年xx月xx日 星期x
* @return
*/
public String getNowDateAndWeek() {
try {
return dateSimple2.format(new Date());
} catch (Exception e) {
return null;
}
}
以上就介绍了android 获取时间的工具类,包括了Exception方面的内容,希望对Android开发有兴趣的朋友有所帮助。
本文网址链接:http://www.codes51.com/article/detail_219719.html