专门提供的LogUtils
public class LogUtils {
public static final boolean isDebug = true;//可以在application的onCreate()中初始化
private static String TAG = "ida";
public static void i(String msg) {//info 信息
if (isDebug) {
Log.i(TAG, msg);
}
}
public static void e(String msg) {//error 错误
if (isDebug) {
Log.e(TAG, msg);
}
}
public static void d(String msg) {//debug 调试
if (isDebug) {
Log.d(TAG, msg);
}
}
public static void w(String msg) {//warn 警告
if (isDebug) {
Log.w(TAG, msg);
}
}
// 自己定义的tag
public static void i(String tag,String msg) {//info
if (isDebug) {
Log.i(tag, msg);
}
}
public static void e(String tag,String msg) {//error
if (isDebug) {
Log.e(tag, msg);
}
}
public static void d(String tag,String msg) {//debug
if (isDebug) {
Log.d(tag, msg);
}
}
public static void w(String tag,String msg) {//warn
if (isDebug) {
Log.w(tag, msg);
}
}
}
时间的工具类 包括时间戳转化为字符串,字符串转化为时间戳,获得当前月份以及前11个月份的集合
/**
* Created by ida on 18-2-8.
*/
public class TimeUtils {
//将时间戳转化为日期字符串
public static String toDate(long time) {
String date = "";
Date d = new Date(time);
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
date = format.format(d);
return date;
}
//将日期字符串转化为时间戳
public static long toTime(String date) {
long time = 0;
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
try {
Date date1 = format.parse(date);
time = date1.getTime();
} catch (ParseException e) {
e.printStackTrace();
}
return time;
}
//当前月份的前11个月(总共12个月)
public static ArrayList<String> year() {
ArrayList<String> list = new ArrayList<>();
Calendar cal = Calendar.getInstance();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM");
String today = dateFormat.format(cal.getTime());
list.add(today);
for (int i = 0; i < 11; i++) {
if (cal.get(Calendar.MONTH) - i < 1) {
list.add(cal.get(Calendar.YEAR) - 1 + "-" + fillZero(cal.get(Calendar.MONTH)-i+12));
} else {
list.add(cal.get(Calendar.YEAR) + "-" + fillZero(cal.get(Calendar.MONTH) - i));
}
}
return list;
}
private static String fillZero(int i) {
String str = "";
if (i > 0 && i < 10) {
str = "0" + i;
} else {
str = i + "";
}
return str;
}