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();
}
アンドロイド:あなたは純粋なアンドロイドを使用している場合は、日付と時刻
public String timezone = TimeZone.getDefault().getID();
を取得し、あなたがJavaを使用している場合は、に以下のコードをたどることができ、タイムゾーン
を取得するには、上記に従うことができますするにはあなたはアンドロイドのOnCreate
を使用している場合は、印刷日時
http://beginnersbook.com/2013/05/current-date-time-in-java/この
を参照してください。
私のコードを使用して..私はあなたの時間はあなたのコードにログアウトされていない意味場合は、時間用にフォーマットされていないこの
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);
}
はあなたが変数で日付と時刻を取得するのですか?または唯一の問題は日時がログに表示されないことですか? – sugansoft
@sugansoft日付と時刻がログに表示されない –
書き込みログe( "currentDateandTime"、 "" + currentDateandTime);日付と時間を取得するために –