2017-07-26 4 views
-1

マイコード.ITは日付が表示されない値をログに記録しながらのAndroid-JavaでAndroidの集合日時がログ猫に表示されていない

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(); 
     } 

を日付と時刻を取得するために使用される

と時間...誰も私を助けることができますか?

+0

はあなたが変数で日付と時刻を取得するのですか?または唯一の問題は日時がログに表示されないことですか? – sugansoft

+0

@sugansoft日付と時刻がログに表示されない –

+0

書き込みログe( "currentDateandTime"、 "" + currentDateandTime);日付と時間を取得するために –

答えて

1
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); 
} 
+0

純粋なアンドロイドでは、純粋なアンドロイドで時間を表示する方法はありません。 –

+0

純粋なアンドロイドはコードを使用して、値を取得することを確認します。java.util.TimeZoneをインポートします。 public String timezone = TimeZone.getDefault()。getID(); – sugansoft

+0

また、このString mydate = java.text.DateFormat.getDateTimeInstance()。format(Calendar.getInstance()を試すこともできます。時間をもらう()); – sugansoft

0

のための出力を得ました。このようにフォーマットしなければならない時間を表示する。

  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を返しません。 &ヌルでない場合はログアウトしてください。

Log.e( "TAG"、 "+ new Date());

と空の文字列が表示されているかどうかを確認してください。それに応じてデバッグを進めてください。

0

あなたはこのように、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(); 
+0

私のログファイルにログの日時が記録されていません。私はそれぞれの行に日付と時刻を入れたい –