我有一个字符串 x = “1086073200000” 。这基本上是毫秒,我需要将其转换为日期。
要转换我正在使用
DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
long tempo1=Long.parseLong(x);
System.out.println(tempo1); // output is 86073200000 instead of the whole thing
long milliSeconds=1346482800000L;
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(milliSeconds);
System.out.println(formatter.format(calendar.getTime()));
问题是当我将字符串 x 转换为 long 时,由于 long 的大小限制,一些数字消失了。
如何保留整个字符串。
谢谢。
原文由 jseth 发布,翻译遵循 CC BY-SA 4.0 许可协议
DateFormat formatter = new SimpleDateFormat(“dd/MM/yyyy”);
long milliSeconds= Long.parseLong(x); System.out.println(milliSeconds);
Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(milliSeconds); System.out.println(formatter.format(calendar.getTime()));
”`