使用adb查看 设置系统时间的格式
public static void setSystemTime(String time) {
try {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
Date date = format.parse(time);
Process process = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(process.getOutputStream());
String formatDate;
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
format = new SimpleDateFormat("MMddHHmmyyyy.ss");
formatDate = format.format(date);
os.writeBytes("date " + formatDate + " set \n");
os.writeBytes("busybox hwclock -w\n");
} else {
format = new SimpleDateFormat("yyyyMMdd.HHmmss");
formatDate = format.format(date);
os.writeBytes("/system/bin/date -s " + formatDate + "\n");
os.writeBytes("clock -w\n");
}
os.writeBytes("exit\n");
os.flush();
} catch (Exception e) {
e.printStackTrace();
}
}
网友评论