2014-04-03 110 views
0

我想當前時間轉換這樣的格式:Android的日期格式時間戳輸出爲 「/日期(1393346946000 + 0200)/

」/日期(1393346946000 + 0200)/

我如何能做到這一點?

public static Date getCurrentTime() { 
     Calendar c = Calendar.getInstance(); 
     System.out.println("Current time => " + c.getTimeInMillis()); 
     long time = (System.currentTimeMillis()); 

     System.out.println("Current time2 => " + time); 
     Date currentTime = c.getTime(); 
     return 
       currentTime; 

    } 

回答

0

用這個來獲取當前時間你想要的格式...

String inputPattern = "yyyy-MM-dd hh:mm:ss"; 
    String outputPattern = "dd/MM";//here you can give your output format that's all 

    SimpleDateFormat inFormat = new SimpleDateFormat(inputPattern); 
    SimpleDateFormat outputFormat = new SimpleDateFormat(outputPattern); 
    Date date1 = null; 

    if (date != null) { 
     try { 
      date1 = inFormat.parse(date); 
      str = outputFormat.format(date1); 
      Log.d(null, str); 
     } catch (ParseException e) { 
      e.printStackTrace(); 
     } 

    } else { 
     str = " "; 
    } 
相關問題