在Java中转换DateTimeFormat!

| 我只需要一个有关Java中DateTime格式的小帮助。我正在编写一个基于yahoo messanger的简单聊天应用程序,在其中我将读取yahoo messanger的数据包并显示聊天消息。现在我想从中显示时间在特定文章中,据说“时间戳记”将是0x477BBA61(十进制1199290977),表示“星期三,2008年1月2日16:22:57 GMT”。 我试图揭示如何将小数转换为该特定日期。我试图编写一个简单的Java应用程序以将其转换为其他时间。
  public static void main(String[] arg)
        {
             Calendar  obj = Calendar.getInstance();
          obj.setTimeZone(TimeZone.getTimeZone(\"GMT\"));
            obj.setTimeInMillis(1199290977l);
          System.out.println( obj.get(Calendar.HOUR)+\":\"+obj.get(Calendar.MINUTE));
        }

output:9:8
有人可以帮我吗?     
已邀请:
您的值1199290977L是错误的。自Unix纪元(1970年1月1日午夜)以来,以秒为单位进行测量-您需要将其乘以1000,以获取自该纪元以来的毫秒数。 您还使用的是12小时制的ѭ1instead,而不是24小时制的ѭ2clock。这段代码:
Calendar  obj = Calendar.getInstance();
obj.setTimeZone(TimeZone.getTimeZone(\"GMT\"));
obj.setTimeInMillis(1199290977000L);
System.out.println(obj.get(Calendar.HOUR_OF_DAY) + \":\" + 
                   obj.get(Calendar.MINUTE));
...打印16:22。 但是,您绝对应该使用
java.text.DateTimeFormat
类而不是自己这样做-或者,理想情况下,请使用Joda Time。     
Imho要继续,您需要知道:
whether or not that number is milliseconds or not
what is the starting point (in java is  January 1, 1970, 00:00:00 GMT)
    
时区可能以秒为单位;尝试将值乘以1000来获得
Calendar
期望的毫秒数。     
您需要使用SimpleDateFormat-查看文档,它很容易理解,并且其中包含很多示例(因此,您无需搜索\“日期格式教程\”或类似的东西:) ) 编辑:糟糕,我错过了您以秒而不是毫秒为单位的时间传递方式,结果时间是错误的,我误解了您的问题,并认为您只想解析时间,乔恩的答案更好:)     

要回复问题请先登录注册