Twi*_*ler 4 android date unix-timestamp
即时尝试将字符串(使用unix时间戳)转换为格式为日期的日期(dd-MM-yyyy)
这部分是有效的.我现在的问题是我的约会时间是17-01-1970(而不是2015年3月16日)
即时转换它像这样:
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
Date d = null;
int dateMulti = Integer.parseInt(Date);
Calendar cal = Calendar.getInstance(Locale.ENGLISH);
cal.setTimeInMillis(dateMulti);
String date = DateFormat.format("dd-MM-yyyy", cal).toString();
Log.d("test",date);
try {
d = dateFormat.parse(date);
} catch (ParseException e) {
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
其中Date = 1427101853,结果= 17-01-1970
我究竟做错了什么?
Jes*_*per 21
您在第一行使用了错误的格式字符串:
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-mm-yyyy");
Run Code Online (Sandbox Code Playgroud)
mm是分钟.使用MM(月)代替.
编辑 Unix时间戳是一个数字的秒因为01-01-1970 00:00:00 GMT.Java测量自格林威治标准时间01-01-1970 00:00:00以来的时间(以毫秒为单位).您需要将Unix时间戳乘以1000:
cal.setTimeInMillis(dateMulti * 1000L);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7292 次 |
| 最近记录: |