在iOS中将日期转换为第二天的日期

编程入门 行业动态 更新时间:2024-10-27 22:24:07
本文介绍了在iOS中将日期转换为第二天的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个字符串格式的日期,就像 30-11-2012 一样。我希望它的旁边的日期再次像字符串格式 01-12-2012 。 有没有办法得到它?

I have a date in string format just like 30-11-2012. I want the date next to it like 01-12-2012 again in string format. Is there any way of getting it?

推荐答案

我得到了一个我忘了名字的答案,我是即将接受他/她的回答,但当我点击接受回答时,它告诉我帖子已被删除。

I got the answer by someone I forget the name, I was about to accept his/her answer but when I clicked on accept answer it told me that the post bas been removed.

该匿名人士给出的答案如下: / p>

The answer given by that anonymous person was given below

NSString *dateString = @"22-11-2012"; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"dd-MM-yyyy"]; NSDate *dateFromString = [[NSDate alloc] init]; dateFromString = [dateFormatter dateFromString:dateString]; NSDateComponents *components= [[NSDateComponents alloc] init]; [components setDay:1]; NSCalendar *calendar = [NSCalendar currentCalendar]; NSDate *dateIncremented= [calendar dateByAddingComponents:components toDate:dateFromString options:0]; NSDateFormatter *myDateFormatter = [[NSDateFormatter alloc] init]; [myDateFormatter setDateFormat:@"dd-MM-yyyy"]; NSString *stringFromDate = [myDateFormatter stringFromDate:dateIncremented]; NSLog(@"%@", stringFromDate);

最后我真的要感谢那个匿名的人,我知道这不是那么棘手但是这对我帮助很大。再次感谢Anonymous Helper。

In the end I really like to thanks that anonymous person, I know this was not as much tricky but this helped me a lot. Thanks again you the Anonymous Helper.

更多推荐

在iOS中将日期转换为第二天的日期

本文发布于:2023-11-24 02:51:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1623703.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:日期   第二天   转换为   中将   iOS

发布评论

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

>www.elefans.com

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