Java:时代日期为MM / DD / YYYY [英] Java: epoch date to MM/DD/YYYY

查看:120
本文介绍了Java:时代日期为MM / DD / YYYY的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的时间:1386696238

My time: 1386696238

我的代码:

Date date = new Date(Long.parseLong(currentNotification.getDate_created()));
        SimpleDateFormat formatter = new SimpleDateFormat("MM/DD/yyyy", Locale.getDefault());
        String dateString = formatter.format(date);

我的结果: 1/16/1970

所需结果: 12/10/2013

我做错了什么?

推荐答案

你的值在几秒钟内,所以你需要乘以1000.

Your value is in seconds, so you need to multiply it by 1000.

另外, DD 是一年的一天,你想要 dd

Also, DD is day of year, you want dd:

SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy", Locale.getDefault());

这篇关于Java:时代日期为MM / DD / YYYY的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆