我有super()
有约会。我正在尝试将该日期转换为NSString
。当我这样做时,我从NSDate
获得nil
。这是我的代码:
NSDate
以下是NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"dd/MM/yyyy"];
NSDate *date = [dateFormatter dateFromString:dateString];
NSLog(@"dateString = %@ date = %@", dateString, date);
:
NSLog
我做错了什么,我该如何解决?
答案 0 :(得分:3)
日期格式与日期字符串不匹配。它必须是:: @" yyyy-MM-dd"
订单和其他字符需要匹配 yyyy四位数年份 MM为两位数的月份 dd为两位数的日子
请参阅:ICU Formatting Dates and Times
注意:DECLARE @t TABLE (val INT)
INSERT INTO @t (val) VALUES (420),(420),(520),(520),(520),(620)
--SELECT val,ROW_NUMBER()OVER(PARTITION BY val order by val)RN from @t
DECLARE @t2 table (id INT identity(1,1), val INT, rn INT)
DECLARE @val INT
DECLARE @rn INT
DECLARE @val_prev INT
DECLARE CUR CURSOR FOR
SELECT val
,ROW_NUMBER()OVER(PARTITION BY val ORDER BY val)RN
FROM @t
ORDER BY val ASC
OPEN CUR
FETCH NEXT FROM cur
INTO @val, @rn
SET @val_prev = @val
WHILE @@FETCH_STATUS = 0
BEGIN
IF @val_prev <> @val BEGIN
INSERT @t2 (val,rn) VALUES (NULL, NULL)
SET @val_prev = @val
END
INSERT @t2 (val,rn) VALUES (@val, @rn)
FETCH NEXT FROM cur
INTO @val, @rn
END
CLOSE cur;
DEALLOCATE cur;
SELECT * FROM @t2 ORDER BY id
使用NSLog()
NSDate
方法,该方法提供以GMT(UTC)为参考的日期/时间,并且description
默认为您的时区,因此显示的日期可能是不同。