将NSDate格式化为DDMMYYYY? [英] format a NSDate to DDMMYYYY?

查看:103
本文介绍了将NSDate格式化为DDMMYYYY?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须从日期发送DDMMYYY日期以与API通信。

I have to send a DDMMYYY date from a Date to communicate with an API.

NSDateComponents * dateComponents;
NSCalendar * gregorian;
NSDate * date;

NSDateComponents *dateComponents; NSCalendar *gregorian; NSDate *date;

gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];

dateComponents = [[NSDateComponents alloc] init];
self.date = [gregorian dateByAddingComponents:dateComponents toDate:[NSDate date] options:0];

我是否必须使用[dateComponents日]等等?是否有一些方法可以帮助我像PHP一样执行该任务?

Do I have to use the [dateComponents day] and so on? is there some method that can help me to performing that task like in PHP?

推荐答案

试试这个

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"ddMMyyyy"];
NSString *textDate = [NSString stringWithFormat:@"%@",[dateFormatter stringFromDate:[NSDate date]]];
NSLog(@"Date %@",textDate);
[dateFormatter release];

这篇关于将NSDate格式化为DDMMYYYY?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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