[問題] 如何將4 BYTES轉成日期輸出?!

看板java作者 (o(˙﹏˙)o  狗年好狗運)時間18年前 (2007/05/21 21:41), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
我想要將4 BYTES資料轉成DATE格式 我查到C是這樣子寫. //unsigned long int to time string char* ul2tstr(unsigned long int ul){ char *tstr = new char[20]; time_t t = (time_t)ul; //strcpy(tstr, ctime(&t)); struct tm *t_struct = localtime(&t); strftime(tstr, 20,"%Y/%m/%d %H:%M:%S" , t_struct); return tstr; } 我在java是寫成這樣,length是傳入4 private String u12tstr(byte[] header,int start,int length) { if (length==0) return -1; int result = header[0] & 0xFF; for(int i=1;i<b.length;i++) { result |= ((header[start] << 8*i) & (0xFF)*(int)Math.pow(256,i)); start = start + 1; } return result+""; } 請問我該怎樣改呢?! 才可以讓他輸出上面那種 YYYY/MM/DD HH:MM:SS格式呢?! -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.230.236.50 ※ 編輯: onfly 來自: 61.230.236.50 (05/21 22:35)
文章代碼(AID): #16KQ6NL6 (java)