Java Android设置日期和时间未显示在日志cat中
我的代码 用于在Android Java中获取日期和时间Java Android设置日期和时间未显示在日志cat中,java,android,datetime,Java,Android,Datetime,我的代码 用于在Android Java中获取日期和时间 try { SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd", Locale.US); String currentDateandTime = sdf.format(new Date()); final File path = new File(Environme
try {
SimpleDateFormat sdf = new SimpleDateFormat(
"yyyy-MM-dd", Locale.US);
String currentDateandTime = sdf.format(new Date());
final File path = new File(Environment.getExternalStorageDirectory(), "SMOK_komunal");
if (!path.exists()) {
path.mkdir();
}
Log.e("path ", path.getAbsolutePath()+ " and "+currentDateandTime );
Runtime.getRuntime().exec("logcat -f " + path + File.separator + "dbo_logcat_" + currentDateandTime + ".txt");
} catch (IOException e) {
e.printStackTrace();
}
记录值时。它不显示日期和时间。。。有人能帮我吗
try {
SimpleDateFormat sdf = new SimpleDateFormat(
"yyyy-MM-dd", Locale.US);
String currentDateandTime = sdf.format(new Date());
final File path = new File(Environment.getExternalStorageDirectory(), "SMOK_komunal");
if (!path.exists()) {
path.mkdir();
}
Log.e("path ",""+path.getAbsolutePath());
Log.e("Currentdateandtime",""+currentDateandTime );
Runtime.getRuntime().exec("logcat -f " + path + File.separator + "dbo_logcat_" + currentDateandTime + ".txt");
} catch (IOException e) {
e.printStackTrace();
}
Android:获取日期和时间
public String timezone = TimeZone.getDefault().getID();
如果你使用的是纯安卓系统,你可以按照上面的方法来获取时区
如果您使用的是java,则可以按照以下代码打印日期和时间
参考此
如果您使用的是android oncreate
使用我的代码。。我得到了这个的输出
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.main);
Calendar c = Calendar.getInstance();
System.out.println("Current time => "+c.getTime());
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String formattedDate = df.format(c.getTime());
// formattedDate have current date/time
Toast.makeText(this, formattedDate, Toast.LENGTH_SHORT).show();
// Now we display formattedDate value in TextView
TextView txtView = new TextView(this);
txtView.setText("Current Date and Time : "+formattedDate);
txtView.setGravity(Gravity.CENTER);
txtView.setTextSize(20);
setContentView(txtView);
}
如果您的意思是时间没有在代码中注销,那么您还没有格式化时间。为了显示时间,你必须这样格式化
SimpleDateFormat sdf = new SimpleDateFormat(
"yyyy.MM.dd G 'at' HH:mm:ss z", Locale.US);
String currentDateandTime = sdf.format(new Date());
Log.e("TAG"," and "+currentDateandTime );
或者你的意思是即使你的约会对象也没有注销。确定
新日期
未返回null如果不为null,请尝试注销
Log.eTAG和+新日期
看看它是否显示了一个空字符串。并相应地进行调试。您应该在执行logcat命令后进行日志记录,如下所示:
try {
SimpleDateFormat sdf = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss z", Locale.US);
String currentDateandTime = sdf.format(new Date());
final File path = new
File(Environment.getExternalStorageDirectory(), "SMOK_komunal");
if (!path.exists()) {
path.mkdir();
}
Runtime.getRuntime().exec("logcat -f " + path + File.separator
+ "dbo_logcat_" + currentDateandTime + ".txt" + " *:E");
Log.e("path ",""+path.getAbsolutePath());
Log.e("Currentdateandtime",""+currentDateandTime );
} catch (IOException e) {
e.printStackTrace();
您是否获得了变量中的日期和时间?或者您唯一的问题是日志中没有显示日期和时间?@sugansoft日志写入日志中没有显示日期和时间。ecurrentDateandTime,+currentDateandTime;为了得到日期和时间,我已经回答了你。。如果它的作品接受我的回答可能你有一个例外在纯android中我没有日期和时间如何在纯android中显示时间?纯android使用代码并检查你将获得值import java.util.TimeZone;公共字符串timezone=timezone.getDefault.getID;您还可以尝试使用以下字符串mydate=java.text.DateFormat.getDateTimeInstance.formatCalendar.getInstance.getTime;这是我的日志行在文件:E/set caption DI32499:Lista Tras-data akt中的样子。2017年7月26日Pojazd czajniczekAnd我需要在我的日志中输入日期和时间,但我的日志行中没有记录日期和时间。我想在每行写上日期和时间