Android的Google日历是不会放弃的预期结果 [英] Android Calendar is not giving expected results

查看:124
本文介绍了Android的Google日历是不会放弃的预期结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我传递值的日历实例,但不知道为什么它预期不执行。我希望有一天能加入到一个特定的日期,然后使用该日期。

I am passing values to calendar instance, but don't know why it is not performing as expected. I want to add one day to a specific date and then use that date.

Log.v("data going to calendar==",
  "year="+Integer.parseInt(fy)+
  "month="+Integer.parseInt(fm)-1)+
  "day="+Integer.parseInt(fd)+
  "hh="+Integer.parseInt(fh)+
  "mm="+Integer.parseInt(fmn));

c.set(
  Integer.parseInt(fd),
  Integer.parseInt(fm)-1,
  Integer.parseInt(fy),
  Integer.parseInt(fh),
  Integer.parseInt(fmn));

c.add(Calendar.DAY_OF_MONTH,1);

Log.v("data coming from calendar==", 
   "year = " + c.get(Calendar.YEAR)+
   "month ="+ c.get(Calendar.MONTH)+
   "day ="+c.get(Calendar.DATE)+
   "hh="+c.get(Calendar.HOUR)+
   "mm="+c.get(Calendar.MINUTE));

输出是:
数据GNG日历==年=2013个月=7天= 29hh =12毫米= 0

output is: data gng to calendar==year = 2013month =7day =29hh=12mm=0

数据cmng ==年=35个月=1天= 4HH为0mm = 0

data cmng from calendar==year = 35month =1day =4hh=0mm=0

我通过把评论code添加一个一天运行code,但结果仍然是,除了天一样,这意味着增加一个一天工作完美--->
年=35个月=1天= 3HH为0mm = 0

i run that code by putting comment on code to add one day, but the results are still same except for day, it means adding one day is working perfectly ---> year = 35month =1day =3hh=0mm=0

推荐答案

您拨打设置()方法与错误的参数。根据本<一href=\"http://docs.oracle.com/javase/7/docs/api/java/util/Calendar.html#set%28int,%20int,%20int,%20int,%20int%29\"相对=nofollow>文档顺序必须是日期作为前三个参数,你把它叫做日期作为第一个参数。

You call the set() method with the wrong parameters. According to the documentation the order must be year, month, date as first three parameters and you call it with date, month, year as the first parameters.

如果你改变code到

c.set(Integer.parseInt(fy),
    Integer.parseInt(fm)-1,
    Integer.parseInt(fd),
    Integer.parseInt(fh),
    Integer.parseInt(fmn));

它应该工作打算。

it should work as intended.

但奇怪的值是因为它把 2013 为天是约。 6年被添加到日期

The strange values are because it treats 2013 as the day which is approx. 6 years that are added to the date.

这篇关于Android的Google日历是不会放弃的预期结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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