[英]IOS:string split of date
I have a date in the format: 22-10-2013
and I want to show the date in the pdf as 22-10, 2013
. 我有一个日期格式: 22-10-2013
,我想在pdf中显示日期为22-10, 2013
。 In the pdf only it is shown as -----,20--
. 仅在pdf中显示为-----,20--
。 I have to fill the date in the blank spaces. 我必须在空白处填写日期。
NSDateFormatter *dateFormatter = [NSDateFormatter new];
[dateFormatter setDateFormat:"dd-MM, yyyy"];
NSString *dateString= [dateFormatter stringFromDate:yourDate];
With this you can specify your format you want to output, it will output: 22-10, 2013
exactly as you wanted. 使用此选项,您可以指定要输出的格式,它将完全按照您的要求输出: 22-10, 2013
。
Apply this: 应用此:
[DrawPdf drawString:[NSString StringWithFormat:@"Issued in Columbia, Missouri on %@.", dateString] OfFont:12 atRect:CGRectMake(currentX, currentPageY, 500, 20)];
try like this , 这样尝试,
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"dd-MM-yyyy"];
NSDate* date = [formatter dateFromString:@"22-10-2013"];
[formatter setDateFormat:@"dd-MM,yyyy"];
NSString* output = [formatter stringFromDate:date];
O/P:- 22-10,2013
O / P:- 22-10,2013
年10月22-10,2013
NSDateFormatter* dateFormatter = [[NSDateFormatter alloc]init];
[dateFormatter setDateFormat:@"dd-MM,yyyy"];
NSString *result = [dateFormatter stringFromDate:[NSDate date]];
NSDateFormatter *format = [[NSDateFormatter alloc] init];
[format setDateFormat:@"dd-MM-yyyy"];
NSDate *date = [format dateFromString:@"22-10-2013"];
[format setDateFormat:@"dd-MM,yyyy"];
NSString *newFormat = [format stringFromDate:date];
This newFormat
will give you the required format of date you need. 此newFormat
将为您提供所需的日期格式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.