我需要將當前日期時間轉換爲"04/10/2013 12:00:00 GMT+5:00"
格式。 我已經通過不同的方法,但無法得到確切的格式。 任何人都可以知道,請幫助我。在iphone中轉換日期時間
-4
A
回答
0
// String To Date Conversion
NSString *dateStr = @"5/13/2012 6:05 am";
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"M/d/yyyy h:mm a"];
NSDate *myDate = [dateFormatter dateFromString:dateStr];
// This converts time to GMT local timezone
NSDateFormatter* df_local = [[[NSDateFormatter alloc] init] autorelease];
// calculate Number of seconds upto 5hrs(GMT+5000) seconds = 18000, if its GMT+0530 then seconds = 19800
// Set TimeZone Accordingly
[df_local setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:18000]];
// Set your Date Formate
[df_local setDateFormat:@"MM/dd/yyyy hh:mm:ss"];
// Your Final Output String
NSString* ts_local_string = [NSString stringWithFormat:@"%@ %@",[df_local stringFromDate:myDate],[[df_local timeZone] name]];
NSLog(@"Final string : %@",ts_local_string);
NSString* anotherFormat = [NSString stringWithFormat:@"%@ %@",[df_local stringFromDate:myDate],[[df_local timeZone] abbreviation]];
NSLog(@"OUtput : %@",anotherFormat);
OUTPUT:最終的字符串:2012年5月13日五時35分00秒GMT + 0500
+0
如何將時區作爲GMT + 05:00而不是GMT + 0500 – krishna 2013-05-14 09:23:56
+0
我已經按照所需的格式編輯了答案。 ,讓我知道見解。 – 2013-05-14 09:31:21
0
NSDateFormatter *format = [[NSDateFormatter alloc] init];
[format setDateFormat:@"MMM, dd, yyyy HH:mm:ss Z"];
NSDate *now = [NSDate date];
NSString *dateString = [format stringFromDate:now];
2
NSDate *myDate = [NSDate date];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"dd/MM/yyyy hh:mm:ss ZZZ"];
NSString * dateString = [formatter stringFromDate:myDate];
這將是在12個小時的格式。如果你想24小時格式替換HH與HH。
相關問題
- 1. 在SQL中轉換日期的時間
- 2. 在R中的日期時間轉換
- 3. Informatica日期/時間轉換
- 4. 轉換日期時間IST
- 5. ASP.NET日期/時間轉換
- 6. 轉換日期時間
- 7. 日期時間轉換PHP
- 8. 轉換爲日期時間
- 9. 轉換日期時間
- 10. 日期/時間轉換
- 11. 日期時間轉換
- 12. XSLT轉換日期時間
- 13. SQL日期時間轉換
- 14. 轉換PHP日期時間
- 15. 日期時間轉換
- 16. SQL日期時間轉換
- 17. 日期時間轉換
- 18. 日期和時間轉換
- 19. SQL轉換日期時間
- 20. 日期時間轉換器
- 21. 轉換日期時間,以時間
- 22. 將日期時間轉換爲時間
- 23. MPXJ在.NET中的Java日期轉換爲.NET日期時間
- 24. Rails在'where'查詢中將日期時間轉換爲日期
- 25. 問題在C#日期時間轉換
- 26. 轉換日期時間C#在PHP
- 27. 轉換日期時間在軌3.2
- 28. 轉換日期時間在SQL Server
- 29. 日期時間轉換在MySQL和JavaScript
- 30. 轉換XML日期和時間在Delphi
你能提供一些代碼的東西吧。 – iDeveloper 2013-05-14 08:28:49
http://www.roseindia.net/tutorial/iphone/examples/iphone-datetime.html – Buntylm 2013-05-14 08:29:37