English 中文(简体)
为此目的使用日期的最佳方式
原标题:best way of using date for this purpose

这是我第一个应用程序,我需要使用日期

我想使用 Sqlite 数据库以保存当前按键时的日期 。

另外,当单击该按钮时,我要它在文本视图中显示当前日期

现在,我每天都是PHP程序员, 但这对我来说是新鲜的。 我好奇的是, 是否试图使用一个单ix 时间戳(int)是最好的解决办法, 因为这正是我在PHP中用来存储日期的。

在此举一个示例, 说明我当前正在做哪些工作, 以便显示单击按钮后的日期。 以下代码在我的点击函数中, 用于此按钮 :

    long currentTimestamp = System.currentTimeMillis();
    Date theDate = new Date(currentTimestamp);
    String showDate = theDate.getDay() + "/" + theDate.getMonth() + "/" + theDate.getYear() + " " + theDate.getHours() + ":" + theDate.getMinutes();

我开始这样做,但是,在 和机器人文件 它告诉我, 功能,比如得到Day 和得到Month 被折旧 并使用日历函数。

当然,我现在不想开始使用过时的功能,因为对于这个功能来说,这是全新的,不想陷入不良做法,但我读到另一个堆叠溢出的问题,即使用日历比其他解决方案慢。

我只是在寻找答案 如何以最恰当和最有效的方式 来完成这个任务... 谢谢

编辑:

我刚刚读了这个问题:中存储和获取日期时间值

答案之一建议使用一个 unix 时间戳, 这正是我最初想做的。 我展示并存储它时, 将一个 unix 时间戳( 长) 转换为字符串, 并仍然使用日历功能, 是否有办法可以实现此目的?

最佳回答

获取当前时间并将其转换为时间戳 :

long dateInMillis = Calendar.getInstance().getTimeInMillis();

回转 :

Calendar date = Calendar.getInstance();
date.setTimeInMillis(dateInMillis);
问题回答

使用此代码

Calendar month = Calendar.getInstance();

int cal_for_month = month.get(Calendar.MONTH);
int cal_for_year = month.get(Calendar.YEAR);
int cal_for_day = month.get(Calendar.DAY_OF_MONTH);




相关问题
Mysql compaire two dates from datetime?

I was try to measure what is faster and what should be the best way to compare two dates, from datetime record in MySql db. There are several approaches how to grab a date from date time, but I was ...

iPhone Date Picker rolls over to 2010 on December 27th?

So I implemented a UIDatepicker in one of my applications for scheduling and autodialing teleconferences... everything is pretty much ready to go except, while testing I noticed that when the date ...

Convert date Python

I have MMDDYY dates, i.e. today is 111609 How do I convert this to 11/16/2009, in Python?

specifying date format when using $form->inputs() in CakePHP

I am wondering if there is a way to specify the date format in the forms created using CakePHP s $form->inputs(); Please note that this is not the individual $form->input() but instead $form->inputs() ...

NSDateFormat, super simple! Where am I screwing up?

Ok, this is really simple, maybe I m a getting a bit burnt out, but seems like it should work, Query XML feed, put out date string, format, display in a cell. The issue is I m a getting a NULL ...

sqlite writing a date into an email

I am exporting a date value from sqlite and placing it into an email. The date appears like this 279498721.322872 I am using Objective C in an Iphone App. Does anyone know how to make this export ...

热门标签