准确的日期格式和比较日期在iPhone开发? [英] Accurate date formate and compare date in iphone dev?

查看:100
本文介绍了准确的日期格式和比较日期在iPhone开发?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是iphone的新手,我想将字符串更改为准确的日期格式,我在过去2小时内无法完成此操作。我有字符串(10月17日17:30)并希望将其转换为准确的格式,并将此日期与明天进行比较,如果明天再显示10月18日,如果它今天只显示时间17:30,请任何帮助请。

I am new in iphone, i want to change string into accurate date-formate which i couldn't done this for last 2 hrs. I have string like(17:30 18 Oct) and want to convert this in accurate formate and also compare this date to tomorrow if this in tomorrow then display just 18 Oct and if it on today just display time 17:30, any help please.

推荐答案

NSString转换为NSDate

NSString to NSDate conversion

    NSString *dateString = @"6:30 18 Oct";
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"hh:mm dd/MMM"];
    NSDate *dateFromString = [[NSDate alloc] init];
    dateFromString = [dateFormatter dateFromString:dateString];
    [dateFormatter release];

这篇关于准确的日期格式和比较日期在iPhone开发?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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