你好,歡迎來到IOS教程網

 Ios教程網 >> IOS訊息 >> 關於IOS >> ios中如何將一串數字傳化成時間

ios中如何將一串數字傳化成時間

編輯:關於IOS

//把數字轉化成時間如下:

NSString*time = @"1329038338";

NSDateFormatter *formatter = [[[NSDateFormatter alloc] init]autorelease];
[formatter setDateStyle:NSDateFormatterMediumStyle];
[formatter setTimeStyle:NSDateFormatterShortStyle];
[formatter setDateFormat:@"YYYY-MM-dd HH:mm"];
NSDate*confromTimesp = [NSDate dateWithTimeIntervalSince1970:(NSTimeInterval)[time intValue]];
NSString*confromTimespStr = [formatter stringFromDate:confromTimesp];

timeString = confromTimespStr;

//把時間轉化成數字如下:

NSDate*date = [NSDatedate];

NSDateFormatter *formatter1 = [[[NSDateFormatteralloc] init]autorelease];

[formatter1 setDateStyle:NSDateFormatterMediumStyle];

[formatter1 setTimeStyle:NSDateFormatterShortStyle];

[formatter1 setDateFormat:@"YYYY-MM-dd HH:mm"];

NSString* timesp = [NSStringstringWithFormat:@"%lld",(longlong)[date timeIntervalSince1970]];

NSLog(@"++++++%@",timesp);

  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved