2016-04-23 134 views
1

我在設備中獲取時間,它將以GMT格式返回時間,並將其轉換爲本地。將阿拉伯數字轉換爲英文字符串

我得到的時間是例如:23:00,當切換到區域設置它返回阿拉伯數字,當我從JSON的時間,它不會切換到阿拉伯語。

代碼:

private String GMTToLocal(String InputText){ 
    SimpleDateFormat inputFormat = new SimpleDateFormat 
      ("yyyy:M:dd kk:mm", Locale.US); 
    inputFormat.setTimeZone(TimeZone.getTimeZone("GMT")); 

    SimpleDateFormat outputFormat = 
      new SimpleDateFormat("kk:mm"); 
    // Adjust locale and zone appropriately 
    Date date = null; 
    try { 
     date = inputFormat.parse(InputText); 
    } catch (ParseException e) { 
     e.printStackTrace(); 
    } 
    return outputFormat.format(date); 
} 

我嘗試以下,但沒有奏效:在短

String Tes2 = String.format(Locale.ENGLISH,Arabic_Letters_String); 

的問題,我需要在英文字母/數字,而不是在阿拉伯語的時候,這隻發生在我從我的設備獲取時間時,但如果我從JSON獲取它,它將其作爲英語並將其作爲英語返回,但從設備中,它將其作爲阿拉伯語並將其作爲0值返回(因爲Simpledateformat只有英文,我猜)。

回答

3

SimpleDataFormat有一個構造函數接受Locale。默認情況下使用設備區域設置,因此會給你阿拉伯數字。

SimpleDateFormat outputFormat = new SimpleDateFormat("kk:mm", Locale.US);