Android的转换Unix时间GMT时间 [英] Android Convert Unix Time to GMT time

查看:332
本文介绍了Android的转换Unix时间GMT时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有在转换UNIX时间为格林尼治标准​​时间的麻烦。

我有以下的code,但我想知道如何反之亦然它。

 公共静态字符串GetUnixTime()
    {
                 台历挂历= Calendar.getInstance();
                 长今= calendar.getTimeInMillis();

               返回Long.toString(现在的);
    }
 

解决方案

试试这个

 日期D =新的日期(1308670980000L);
SimpleDateFormat的F =新的SimpleDateFormat(DD.MM.YYYY,HH:MM);
f.setTimeZone(TimeZone.getTimeZone(GMT);
字符串s = f.format(D);
 

I'm having trouble in converting a unix time into GMT.

I have the following code, but I would like to know how to vice versa it.

    public static String GetUnixTime() 
    { 
                 Calendar calendar = Calendar.getInstance(); 
                 long now = calendar.getTimeInMillis(); 

               return Long.toString(now);
    } 

解决方案

Try this

Date d = new Date(1308670980000L);
SimpleDateFormat f = new SimpleDateFormat("dd.MM.yyyy,HH:mm");
f.setTimeZone(TimeZone.getTimeZone("GMT");
String s = f.format(d); 

这篇关于Android的转换Unix时间GMT时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆