我找到了一种方法来将“083752”值(长数据格式的时间戳值)存储到Mysql数据库(type = DateTime)。因此,我需要将该值转换为人类可读的日期时间。我使用以下代码来做到这一点。
long l = 083752;
Date date = new Date(l);
System.out.println(date.toString());
修改 我需要做的是83752 => 1/2/1970 4:45:52 AM
但它不起作用。我也跟着这个page。
答案 0 :(得分:1)
如果您以毫秒存储时间,那么
您可以使用java.util.Date类,然后使用SimpleDateFormat格式化Date。
Date date=new Date(millis);
例如:
long l = Long.parseLong("083752"); // mills
DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(l);
System.out.println(formatter.format(calendar.getTime()));
这将返回日期
答案 1 :(得分:0)
我找到了答案。感谢所有支持我的人。
long l = Long.parseLong("083752");
String date1 = new java.text.SimpleDateFormat("MM/dd/yyyy HH:mm:ss").format(new java.util.Date(l * 1000));
System.out.println(date1);