objective-c 字符串怎么转时间

2014-11-28T20:40:31这字符串怎么转时间... 2014-11-28T20:40:31
这字符串怎么转时间
展开
 我来答
水主沉浮6s
2014-12-24 · TA获得超过349个赞
知道小有建树答主
回答量:241
采纳率:0%
帮助的人:209万
展开全部
NSDate类是用来表示时间的,它有一个函数dateWithNaturalLanguageString能从字符串形式的时间生成NSDate对象,但是这个函数好像在高版本不支持了。
用法:
NSDate* myDate = [NSDate dateWithNaturalLanguageString:@“3pm December 31, 2001,”];

下面是苹果网站的内容
链接地址:https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSDate_Class/index.html#//apple_ref/occ/clm/NSDate/dateWithNaturalLanguageString:

Creates and returns an NSDate object set to the date and time specified by a given string.

Declaration

Swift

class func dateWithNaturalLanguageString(_ string: String) -> AnyObject?

Objective-C

+ (id)dateWithNaturalLanguageString:(NSString *)string

Parameters

string

A string that contains a colloquial specification of a date, such as
“last Tuesday at dinner,” “3pm December 31, 2001,” “12/31/01,” or
“31/12/01.”

Return Value

A new NSDate object set to the current date and time specified by string.

Discussion

This method supports only a limited set of colloquial phrases,
primarily in English. It may give unexpected results, and its use is
strongly discouraged. To create a date object from a string, you should
use a date formatter object instead (see NSDateFormatter and Data Formatting Guide).

In parsing the string, this method uses the date and time preferences stored in the user’s defaults database. (See dateWithNaturalLanguageString:locale: for a list of the specific items used.)

Import Statement

import Foundation

Availability

Available in OS X v10.4 and later.
Deprecated in OS X v10.10.
默默凝视那个人
2014-12-24 · TA获得超过225个赞
知道小有建树答主
回答量:384
采纳率:0%
帮助的人:317万
展开全部
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSDate *date = [dateFormatter dateFromString:@"2010-08-04 16:01:03"];
NSLog(@"%@", date);
[dateFormatter release];
使用NSDate和NSString相互转换
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式