如果我尝试下面的代码,例如:
我将日期设置为 2014 年 7 月 25 日星期五上午 10:00。以毫秒为单位的日期为 1402080056000
,
现在,如果我尝试读取相同的毫秒数,如下所示
long time = 1402080056000;
Date mydate = new Date(time);
mydate 变量显示日期为 Sat Jun 25 00:10:56 IST 2014
String DateTimeString = DateFormat.getDateTimeInstance().format(new Date(time));
在 DateTimeString 中使用上述语句,我得到的日期为 Jun 25 , 2014 12:10:56 AM
如何读取 1402080056000 到 Fri July 25 2014 10:00 AM 中的日期时间
最佳答案
只需要处理格式字符串,
String dateTimeString=
String.valueOf(new SimpleDateFormat("dd-MM-yyyy hh:mm").format(new Date(time)));
明确设置时区:
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy hh:mm");
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
String result = String.valueOf(dateFormat.format(millis));
另外,这很有用 Regarding Timezones and Java
关于android - 如何在android中获取标准格式的日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23154443/