将毫秒字符串转换为Java中的日期 [英] Convert millisecond String to Date in Java
问题描述
要转换我正在使用
DateFormat formatter = new SimpleDateFormat(dd / MM / yyyy);
long tempo1 = Long.parseLong(x);
System.out.println(tempo1); //输出是86073200000而不是整个事情
long milliSeconds = 1346482800000L;
日历calendar = Calendar.getInstance();
calendar.setTimeInMillis(milliSeconds);
System.out.println(formatter.format(calendar.getTime()));
问题是当我将字符串x转换为长时,有些数字由于限制
如何保留整个字符串。
THanks。
double tempo = Double.parseDouble(z);
为什么要解析你的 尝试使用 i have a String x = "1086073200000" . This is basically millisecond which I need to convert to a Date. To convert i am using The problem is when i convert the string x to long , some digits go away due to the limit on the size of long. How do I preserve the entire String. THanks. / code> c $ c> c $ c $? b
Long.parseLong
:
DateFormat formatter = new SimpleDateFormat(dd / MM / yyyy);
long milliSeconds = Long.parseLong(x);
System.out.println(milliSeconds);
日历calendar = Calendar.getInstance();
calendar.setTimeInMillis(milliSeconds);
System.out.println(formatter.format(calendar.getTime()));
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()));
double tempo=Double.parseDouble(z);
Why are you parsing your String
which is supposed to be a Long
as a Double
?
Try using Long.parseLong
:
String x = "1086073200000"
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()));
这篇关于将毫秒字符串转换为Java中的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!