Date/Calendar/System三者的时间各不相同,求解释

Sodino 2010-11-01 10:32:54

arg = "201011011028";//当手机时间显示为2010年11月1日10点28分时
int year = Integer.parseInt(arg.substring(0, 4));
int month = Integer.parseInt(arg.substring(4, 6));
int day = Integer.parseInt(arg.substring(6, 8));
int hour = Integer.parseInt(arg.substring(8, 10));
int minute = Integer.parseInt(arg.substring(10, 12));
Date date = new Date(year, month, day, hour, minute);
//此处输出:61249314480000
Log.d("AndroidLabInfo", String.valueOf(date.getTime()));

Calendar calendar = Calendar.getInstance();
calendar.set(year, month, day, day, minute);
//此处输出:1291138110095
Log.d("AndroidLabInfo", String.valueOf(calendar.getTimeInMillis()));
//此处输出:1288578570096
Log.d("AndroidLabInfo", String.valueOf(System.currentTimeMillis()));



三个数各不相同,请问这是为什么呢?

谢谢....
...全文
182 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
ameyume 2010-11-01
  • 打赏
  • 举报
回复
Date侧重日期,是jdk1.0就有的
Calendar是jdk1.1增加的,侧重日历时间,便于国际化时间,是系统推荐使用的。


JAVA的Date类与Calendar类比较
http://sy19861216.javaeye.com/blog/665456
纠结的木棉花 2010-11-01
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 sodino 的回复:]

public Date (int year, int month, int day, int hour, int minute)
Since: API Level 1

This constructor is deprecated.
use GregorianCalendar(int, int, int, int, int)

Constructs a new Date ini……
[/Quote]
It is true
Sodino 2010-11-01
  • 打赏
  • 举报
回复
public Date (int year, int month, int day, int hour, int minute)
Since: API Level 1

This constructor is deprecated.
use GregorianCalendar(int, int, int, int, int)

Constructs a new Date initialized to the specified date and time in the default TimeZone.

Parameters
year the year, 0 is 1900.
month the month, 0 - 11.
day the day of the month, 1 - 31.
hour the hour of day, 0 - 23.
minute the minute of the hour, 0 - 59.


不好意思,看了api之后才明后了,呵呵
Sodino 2010-11-01
  • 打赏
  • 举报
回复
calendar.set(year, month, day, day, minute);
应改为
calendar.set(year, month, day, hour, minute);

写错了,呵呵,但

1291138110095与1288578570096的差距仍然是太大了啊

thegodofwar 2010-11-01
  • 打赏
  • 举报
回复
其实大部分错误的情况是:月份是0-11,而不是1-12这样

80,488

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧