GregorianCalendar的和SQLite [英] GregorianCalendar and SQLite

查看:132
本文介绍了GregorianCalendar的和SQLite的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图安装一个RPG,将跟踪的虚拟时间。经过一番阅读的GregorianCalendar似乎是做到这一点的最好办法,但我有一些问题,希望有经验的人可以给我一些见解。

I'm trying to setup a RPG that will keep track of a virtual time. After some reading GregorianCalendar seems to be the best way to do this but I have some questions and hoping someone with experience could give me some insight.

下面是我想要做的。本场比赛将在1675年启动和运行了近30年。在这一点上的字符将退休,如果他们存活那么久。字符就能从我已经为他们的preSET通过游戏的粗行动选择。有些动作会很短,并采取一个小时,其他人可能需要一周或一个月。真正的问题使用SQLite很大程度上来自于我。我想,以及保存当前的时间,一个动作需要多长时间我的数据库。我首先想到的设置此功能是时候,如果我要开始的比赛中1675年8月15日有我的数据的基础上3行,设置这些领域8个,15个,1675年之后也有时间2个列。通过光标拉这些int和喜欢的东西。

Here is what I'm trying to do. The game will start in the year 1675 and run for about 30 years. At that point the character will retire if they have survived that long. The character will be able to choose from actions I've preset for them through the coarse of the game. Some actions will be short and take a hour, others may take a week or a month. The real question comes from me using SQLite heavily. I want to save the current time as well as how long an action will take in my database. My first thought when setting this up was, if I want to start the game in Aug 15, 1675 to have my data base with 3 rows, set those fields to 8, 15, 1675. Then also have 2 more columns for the time. Pull these int via cursor and set them with something like

GregorianCalendar time = new GregorianCalendar();
time.set(year, month, date, hour, minute);

我想我会拉一个动作需要多长时间以类似的方式。有一个int x,然后一个字符串来讲述这个时间是否以分钟,小时,天等,然后要么添加此INT到INT从数据库中抽取添加到直接在日历中。

I figured I would pull how long an action takes in a similar fashion. Have an int X, and then a string to tell whether this time is in minutes, hours, days etc. Then either add this int to the int pulled from database to add to the calendar directly.

问:如果我直接将它添加到日历如何将我拉从日历int类型在数据库中存储在稍后的时间来加载(当播放器加载自己的游戏)

Q: If I add it directly to the calendar how would I pull int values from the calendar to store in database to load at a later time (when the player loads their game)?

问:如果我把它添加到存储在数据库中的int和这种新的INT设置日历当我添加足以使INT超出范围日历会发生什么(日期被设置为31,但我想补充另一天)?

Q: If I add it to the int stored in the database and set the calendar with this new int what will happen when I add enough to make the int out of scope for the calendar (Date is set to 31 but I add another day)?

推荐答案

您可以从GregorianCalendar对象到/从UNIX时间,例如使用的 getTimeInMillis() setTimeInMillis()。 GregorianCalendar中也有一个卷()方法:

You can convert from the GregorianCalendar object to/from UNIX time for example using getTimeInMillis() setTimeInMillis(). GregorianCalendar also has a roll() method:

将指定金额给指定的字段和包装的价值
  当它超越了最大值或最小值的领域的
  当前日期。根据需要保持其他字段将被调整
  一致的日期。

Adds the specified amount to the specified field and wraps the value of the field when it goes beyond the maximum or minimum value for the current date. Other fields will be adjusted as required to maintain a consistent date.

这篇关于GregorianCalendar的和SQLite的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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