简体   繁体   English

准确的日期格式和比较日期在iPhone开发?

[英]Accurate date formate and compare date in iphone dev?

I am new in iphone, i want to change string into accurate date-formate which i couldn't done this for last 2 hrs. 我是iphone的新手,我想将字符串更改为准确的日期格式,我在最近2小时内无法完成此操作。 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. 我有字符串(10月17日17:30)并希望将其转换为准确的格式,并将此日期与明天进行比较,如果明天再显示10月18日,如果它今天只显示时间17:30,请任何帮助请。

NSString to NSDate conversion NSString转换为NSDate

    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];

Try this 尝试这个

    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
    [dateFormat setDateFormat:@"hh:mma dd/MMM"];
    NSString *dateString = [dateFormat stringFromDate:today];
    NSLog(@"date: %@", dateString);
    [dateFormat release];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM