2015-10-08 4 views
2

нужно показать время в GMT ... но это показывает в UTCКак получить время по Гринвичу в миллисекундах

long m=Long.parseLong("1444588200000"); 

    Date localTime = new Date(m); 

    Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT"), 
      Locale.getDefault()); 
DateFormat date = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss.SSS"); 
String time = date.format(localTime); 
    infoip.setText(" "+time); 
+1

это работает после внесения изменений в настройки в телефоне –

ответ

0

Попробуйте это,

final Date currentTime = new Date(); 

final SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss.SSS"); 

// Give it to me in GMT time. 
sdf.setTimeZone(TimeZone.getTimeZone("GMT")); 
System.out.println("GMT time: " + sdf.format(currentTime)); 
+0

Нет удачи ........ –

+0

Его дает результат, как время по Гринвичу: 08/10/2015 09: 58: 06,002 –

+0

GMT и UTC дисплей то же самое время стоимость. Что вы точно ожидаете? –

0

Попробуйте нравится эта надежда работы.

Calendar cal = Calendar.getInstance(); 

// setting the timezone for which you want 
cal.setTimeZone(TimeZone.getTimeZone("GMT")); 
cal.setTimeInMillis(); 

// The date is in your home timezone 
Date date = cal.getTime(); 
TimeZone tz = TimeZone.getTimeZone("GMT"); 
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss.SSS", Locale.GMT); 
sdf.setTimeZone(tz); 
// Then we do the conversion to convert the date you provided in milliseconds to the GMT timezone 
String result = sdf.parse(date); 
Смежные вопросы