这是为什么产生如3913年 [英] Why is this generating 3913 as the year

查看:119
本文介绍了这是为什么产生如3913年的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一些code,我尝试为一个认购所以这块code的应该转储当前日期的比较中使用。月和日是正确的,但今年是关闭的约1900左右的任何想法,为什么

I wrote some code that I am try to use as a comparison for a subscription so this piece of code was supposed to dump the current date. The month and day are correct but the year is off by about 1900 or so any ideas as to why

    Calendar calendar=Calendar.getInstance();
Date validDate = new Date(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH));
    complain(validDate.toString());

抱怨是我写的只是在一个警告框转储一个字符串到屏幕的值的函数

complain is a function I wrote to simply the dump the value of a string to the screen in an alert box

这表明该3913-02-10

It shows this 3913-02-10

我需要之前,我开始做这个比较固定所以越快越好

I need to get this fixed before I start doing comparisons so the quicker the better

好吧,我增加了一些新的code和不使用depracated日期下去,但现在我一个月是1就说明2013 1 10

OK I added some new code and not using the depracated Date any longer but now my month is of by 1 it shows 2013 1 10

    Calendar cal = Calendar.getInstance();

    int year = cal.get(Calendar.YEAR);
    int month = cal.get(Calendar.MONTH);
    int day = cal.get(Calendar.DAY_OF_MONTH);

    complain(String.valueOf(year) + " " + String.valueOf(month) + " " + String.valueOf(day));

进一步研究后,我发现这个月返回正确的值,但我不得不说这是非常直观的,我觉得它会与日期格式的正常理解一致
这具有一月设置为0,二月1,三月至2等它是非直观的。

After further research I found that MONTH returns the correct value but I have to say this is VERY unintuitive I would think that it would coincide with normal understandings of the date format This has January set to 0, February to 1, March to 2, etc. it is non intuitive.

感谢所有

推荐答案

您正在使用的德precated构造,是以年 - 1900年作为第一个参数

You are using a deprecated constructor that takes the year - 1900 as its first argument.

这篇关于这是为什么产生如3913年的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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