2009-11-10 44 views
3

我从sqlite中导出日期值并将其放入电子邮件中。日期显示是这样的 279498721.322872sqlite将日期写入电子邮件

我在Iphone App中使用Objective C。有没有人知道如何使这个出口作为一个正常的日期,无论它是所有的数字像 2009-02-10或任何清晰的?

+0

你使用什么语言?我知道在C#中,sqlite驱动程序自动处理这类事情。 – FrustratedWithFormsDesigner 2009-11-10 01:09:19

+0

我只是想添加信息,目标C,iPhone应用程序.... thx为要求 – 2009-11-10 01:15:46

回答

1

感谢您的回复。答案来自我的Guru Alex Cone。他告诉我,使用以下命令:

NSTimeInterval tempInterval = (NSTimeInterval)sqlite3_column_double(statement, 4); 

tempInterval变量可以被加载到该NSDate方法。

1
echo date("Y-m-d",time(279498721.322872)); 
+0

我希望我可以使用这个:) – 2009-11-10 01:21:15

2

好吧,如果你把号码279498721.322872,把它扔进使用+dateWithTimeIntervalSinceReferenceDate一个NSDate对象,你(在MDT时区位置):2009-11-09 15:32:01 -0700,这是不到3小时前。如果这是您期待的时间,那么格式化就像使用NSDateFormatter一样简单。

但是,需要注意的是,sqlite(默认情况下)将日期存储为文本表示(除非您在sql语句中指定的内容不同)。所以这里真正的问题是“你从哪里得到这个数字?”

+0

戴夫,谢谢,迄今... NSString * tempString = [NSString stringWithUTF8String :(char *)sqlite3_column_text(statement,1)]; NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@“EEEE,MMMM d,yyyy”]; NSDate * date = [NSDate dateWithTimeIntervalSinceReferenceDate:279498721]; NSString * formattedDateString = [dateFormatter stringFromDate:date]; NSLog(@“formattedDateString:%@”,formattedDateString); 当我尝试放置tempString其中2794 ....编号在系统错误: “不兼容的参数类型。任何想法.Thx – 2009-11-10 05:51:26

+0

@Leland - 是啊。2974 ...是一个数字(原始)你不能传入一个对象。 – 2009-11-10 06:15:29