我收到來自Web服務的日期如/日期(1326067200000)/,我怎樣才能將其轉換爲類似DD.MM.YYYY日的日期?我怎麼能轉換系統毫秒到在Objective-C
6
A
回答
16
您可以使用
NSString *actDate = @"/Date(1326067200000)/";
NSString *nDate = [[[[actDate componentsSeparatedByString:@"("] objectAtIndex:1] componentsSeparatedByString:@")"] objectAtIndex:0];
NSDate *date = [NSDate dateWithTimeIntervalSince1970:([nDate doubleValue]/1000)];
在date
你會得到的實際日期。另外,你可以通過使用
NSDateFormatter *dtfrm = [[NSDateFormatter alloc] init];
[dtfrm setDateFormat:@"MM/dd/yyyy"];
nDate = [dtfrm stringFromDate:date];
在nDate
你會得到你想要的日期在一個格式化的方式在「MM/DD/YYYY」格式進行格式化。
+0
非常感謝。它很棒! – OzBoz 2012-01-10 09:43:48
0
使用NSDate's initWithTimeIntervalSinceReferenceDate:(假設你的價值採用2001年1月1日第一瞬間,格林尼治標準時間爲基準日),以獲得代表你的時間戳的NSDate的實例。
爲了得到一個格式化字符串表示,你可以使用類NSDateFormatter。
0
嘗試......
NSDate *date=[[NSDate alloc] initWithTimeIntervalSinceReferenceDate:gettingdate];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc]init];
[dateFormat setDateFormat:@"dd-MM-yyyy HH:mm:SS"];
NSString *newdate = [dateFormat stringFromDate:date];
0
//Use of Function
textFiled.text = [self displayDate:[[NSString stringWithFormat:@"%@",[[[AllKeys valueForKey:@"Date"] componentsSeparatedByString:@"\"]]]]
// Millisecond to Date conversion
- (NSDate *)displayDate:(double)unixMilliseconds {
NSDate *date = [NSDate dateWithTimeIntervalSince1970:unixMilliseconds/1000.];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateStyle:NSDateFormatterShortStyle];
[dateFormatter setTimeStyle:NSDateFormatterShortStyle];
[dateFormatter setLocale:[NSLocale currentLocale]];
NSLog(@"The date is %@", [dateFormatter stringFromDate:date]);
// NSDate *returnValue = [dateFormatter stringFromDate:date];
return date;
}
+0
'textField.text'期待一個的NSString,但你分配的NSDate對象。什麼是'AllKeys',它與'/ Date(1326067200000)/'有什麼關係 – vikingosegundo 2013-07-11 14:42:17
相關問題
- 1. objectiveC/CMTime - 將AVPlayer.duration轉換爲毫秒
- 2. 轉換MusicTimeStamp(AudioToolbox)到毫秒
- 3. 轉換分鐘到毫秒
- 4. 毫微秒到毫微秒的轉換毫秒數<999999在Java中
- 5. 轉換納秒到毫秒不工作
- 6. 我怎麼能在android系統
- 7. 將時間轉換爲秒+毫秒秒
- 8. 將jiffies轉換爲毫秒
- 9. 轉換毫秒的NSDate
- 10. 轉換時間爲毫秒?
- 11. 將Ecto.DateTime轉換爲毫秒
- 12. 在毫秒中將毫秒轉換爲日期時間
- 13. 毫秒的系統信號在系統verilog不使用$位
- 14. 轉換JulianDate到時間毫秒
- 15. 如何轉換長到毫秒
- 16. 我怎樣才能得到毫秒的日期
- 17. 今天下午6:15我怎樣才能得到UTC毫秒?
- 18. 轉換和微秒和毫秒比較
- 19. 毫秒到秒?
- 20. 在Windows cmd中將系統時間精確到毫秒
- 21. 我怎樣才能在android系統
- 22. 如何將秒錶刻度轉換爲納秒,毫秒和秒?
- 23. 我怎麼能轉換長日期,年?
- 24. 我怎樣才能移動圖像以毫秒字使用C#
- 25. 我怎樣才能獲得視頻時間爲毫秒
- 26. 將ULARGE_INTEGER QuadPart轉換爲毫秒
- 27. 將毫秒轉換爲時間碼
- 28. php:將毫秒轉換爲日期
- 29. 轉換日期爲毫秒黑莓
- 30. 如何將HH:mm:ss.SSS轉換爲毫秒?
毫秒,因爲什麼時候?第0年? – 2012-01-10 09:31:19