将@“dd-MM-yyyy HH:mm:SS”中保存的日期转换为格式为@“dd MM”为了显示方便
我已经以@“dd-MM-yyyy HH:mm:SS”格式保存了日期,现在在数据库中它以指定的格式显示!但我有一个在查看提醒页面中显示日期的要求。因此我想以一种使日期的可见性在外观上简单的方式显示日期。
因此,我希望日期的格式为:1 月 23 日或 8 月 19 日等...
我已尝试以下代码,但它没有显示任何日期:
remin.Date = [[[NSString alloc]initWithUTF8String:(const char *)sqlite3_column_text(statament, 3)]autorelease];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc]init];
[dateFormat setDateFormat:@"MMMM-dd"];
NSDate *date = [dateFormat dateFromString:remin.Date];
NSString *dateVal = [dateFormat stringFromDate:date];
remin.Date = dateVal;
请通过您的宝贵建议提供解决方案,
提前致谢:)
I have saved a date in @"dd-MM-yyyy HH:mm:SS" format,Now in database it gets displayed in what ever format specified! But I have a requirement of displaying date in view reminder page.Hence I would like to display date in such a way that the visibility of date is simple in appearance.
Hence I would like to have the date with say the format:January 23 or August 19 etc...
I have tried the below code but its not displaying any date:
remin.Date = [[[NSString alloc]initWithUTF8String:(const char *)sqlite3_column_text(statament, 3)]autorelease];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc]init];
[dateFormat setDateFormat:@"MMMM-dd"];
NSDate *date = [dateFormat dateFromString:remin.Date];
NSString *dateVal = [dateFormat stringFromDate:date];
remin.Date = dateVal;
Please provide a solution through your valuable suggestions
Thanks in advance :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
尝试下面的代码
Try the following code
将您的代码更改为,
Change your code as,
这是代码:-
Here is the code:-
在解析字符串之前,您需要告诉 NSDateFormatter 字符串的日期格式。
您可能还想将时区存储在数据库中,但这取决于应用程序的要求。要添加时间,请使用此格式
dd-MM-yyyy HH:mm:SS z
You need to tell the
NSDateFormatter
the date format of the string, before you parse it.You might want to also store the time zone in the datebase, but this depends on the apps requirements. To add the time use this format
dd-MM-yyyy HH:mm:SS z