我怎样才能检索IOS不同类型的日期

问题描述 投票:0回答:2

我需要创建一个应用程序,可以采取的日期和时间,从用户。不同位置的用户可以根据自己的位置时区输入日期即美国,亚洲,GB etc..all他们有不同的时间格式,以便将进入不同的日期时间格式,所以我怎么能检索字符串日期?我是否需要设置日期格式每个本地时间?或者有没有在IOS库中的任何内置的功能,从而允许用户输入不同类型的文本框格式日期?请帮忙

NSString *datestring = self.date.text;
NSString *timestring = self.time.text;
NSString *combined = [NSString stringWithFormat:@"%@ %@", datestring, timestring];

这就是我如何从用户的字符串到文本框。是否有任何其他更好的方法?

ios nsdate nsdateformatter
2个回答
1
投票

您可以使用NSDateFormatter将日期字符串转换为NSDate的,并与SETLOCAL玩法:和setDateFormat适当日期格式。

例如:使用日期格式与i设备的本地设置:

NSDateFormatter *df = [[NSDateFormatter alloc] init];
    [df setLocale:[NSLocale currentLocale]];

看看:https://developer.apple.com/library/ios/documentation/cocoa/Conceptual/DataFormatting/Articles/dfDateFormatting10_4.html#//apple_ref/doc/uid/TP40002369-SW1


0
投票

我认为你必须使用UIDatePicker相当的UITextField那么你就需要考虑当地人的欢迎。

© www.soinside.com 2019 - 2024. All rights reserved.