在Sqlite数据库中对日期进行排序(Sort the date in Sqlite database)

编程入门 行业动态 更新时间:2024-10-27 01:20:37
在Sqlite数据库中对日期进行排序(Sort the date in Sqlite database)

我正在制作一个iPhone应用程序,我将日期和时间存储在一个列中,现在我想按照先发生的顺序对日期和时间进行排序。

我怎样才能做到这一点? 请给我一些解决方案。

I am making an iPhone application in which I am storing date and time in a column now I want to sort the date and time in the order which occurs first.

How can I do this? please give me some solutions.

最满意答案

将NSDate另存为NSTimeInterval :

NSTimeInterval timeInterval = [[NSDate date] timeIntervalSince1970];

NSTimeInterval只是一个可以保存在SQLite数据库中的double NSTimeInterval数。

使用简单的SQL查询,您可以选择排序:

SELECT * FROM dateTable ORDER BY myDateColumn DESC

并且让NSDate回归:

NSDate *date = [NSDate dateWithTimeIntervalSince1970:databaseTimeInterval];

Save the NSDate as NSTimeInterval:

NSTimeInterval timeInterval = [[NSDate date] timeIntervalSince1970];

The NSTimeInterval is just a double which you can save in the a SQLite database.

With an simple SQL query you can then select the sort then:

SELECT * FROM dateTable ORDER BY myDateColumn DESC

And to get the NSDate back just:

NSDate *date = [NSDate dateWithTimeIntervalSince1970:databaseTimeInterval];

更多推荐

本文发布于:2023-07-26 19:51:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1280255.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:中对   日期   数据库   Sqlite   date

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!