最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

iOS中時(shí)間與時(shí)間戳的相互轉(zhuǎn)化實(shí)例代碼

 更新時(shí)間:2017年03月10日 11:56:45   作者:張無忌!  
這篇文章主要介紹了iOS中時(shí)間與時(shí)間戳的相互轉(zhuǎn)化實(shí)例代碼,非常具有實(shí)用價(jià)值,需要的朋友可以參考下。

本人搜索了很多關(guān)于iOS中時(shí)間與時(shí)間戳的相互轉(zhuǎn)化的資料,下面我來記錄一下,有需要了解iOS中時(shí)間與時(shí)間戳的相互轉(zhuǎn)化的朋友可參考。希望此文章對(duì)各位有所幫助。

//獲取當(dāng)前系統(tǒng)時(shí)間的時(shí)間戳

#pragma mark - 獲取當(dāng)前時(shí)間的 時(shí)間戳

+(NSInteger)getNowTimestamp{

 NSDateFormatter *formatter = [[NSDateFormatter alloc] init];

 [formatter setDateStyle:NSDateFormatterMediumStyle];

 [formatter setTimeStyle:NSDateFormatterShortStyle];

 [formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"]; // ----------設(shè)置你想要的格式,hh與HH的區(qū)別:分別表示12小時(shí)制,24小時(shí)制

 //設(shè)置時(shí)區(qū),這個(gè)對(duì)于時(shí)間的處理有時(shí)很重要

 NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"Asia/Beijing"];

 [formatter setTimeZone:timeZone];

 NSDate *datenow = [NSDate date];//現(xiàn)在時(shí)間

 

 NSLog(@"設(shè)備當(dāng)前的時(shí)間:%@",[formatter stringFromDate:datenow]);

 //時(shí)間轉(zhuǎn)時(shí)間戳的方法:

 

 NSInteger timeSp = [[NSNumber numberWithDouble:[datenow timeIntervalSince1970]] integerValue];

 

 NSLog(@"設(shè)備當(dāng)前的時(shí)間戳:%ld",(long)timeSp); //時(shí)間戳的值

 

 return timeSp;

}

 

//將某個(gè)時(shí)間轉(zhuǎn)化成 時(shí)間戳

#pragma mark - 將某個(gè)時(shí)間轉(zhuǎn)化成 時(shí)間戳

+(NSInteger)timeSwitchTimestamp:(NSString *)formatTime andFormatter:(NSString *)format{

 

 NSDateFormatter *formatter = [[NSDateFormatter alloc] init];

 [formatter setDateStyle:NSDateFormatterMediumStyle];

 [formatter setTimeStyle:NSDateFormatterShortStyle];

 [formatter setDateFormat:format]; //(@"YYYY-MM-dd hh:mm:ss") ----------設(shè)置你想要的格式,hh與HH的區(qū)別:分別表示12小時(shí)制,24小時(shí)制

 

 NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"Asia/Beijing"];

 [formatter setTimeZone:timeZone];

 

 NSDate* date = [formatter dateFromString:formatTime]; //------------將字符串按formatter轉(zhuǎn)成nsdate

 //時(shí)間轉(zhuǎn)時(shí)間戳的方法:

 NSInteger timeSp = [[NSNumber numberWithDouble:[date timeIntervalSince1970]] integerValue];

 

 NSLog(@"將某個(gè)時(shí)間轉(zhuǎn)化成 時(shí)間戳&&&&&&&timeSp:%ld",(long)timeSp); //時(shí)間戳的值

 

 return timeSp;

}

 

//將某個(gè)時(shí)間戳轉(zhuǎn)化成 時(shí)間

#pragma mark - 將某個(gè)時(shí)間戳轉(zhuǎn)化成 時(shí)間

+(NSString *)timestampSwitchTime:(NSInteger)timestamp andFormatter:(NSString *)format{

 

 NSDateFormatter *formatter = [[NSDateFormatter alloc] init];

 [formatter setDateStyle:NSDateFormatterMediumStyle];

 [formatter setTimeStyle:NSDateFormatterShortStyle];

 [formatter setDateFormat:format]; // (@"YYYY-MM-dd hh:mm:ss")----------設(shè)置你想要的格式,hh與HH的區(qū)別:分別表示12小時(shí)制,24小時(shí)制

 NSTimeZone *timeZone = [NSTimeZone timeZoneWithName:@"Asia/Beijing"];

 [formatter setTimeZone:timeZone];

 NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:timestamp];

 NSLog(@"1296035591 = %@",confromTimesp);

 

 NSString *confromTimespStr = [formatter stringFromDate:confromTimesp];

 

 //NSLog(@"&&&&&&&confromTimespStr = : %@",confromTimespStr);

 

 return confromTimespStr;

}

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

时尚| 定西市| 盐津县| 巴彦县| 安庆市| 兰州市| 汝阳县| 祥云县| 石家庄市| 弥渡县| 瓮安县| 德保县| 青州市| 云和县| 报价| 靖江市| 武邑县| 新乡市| 曲松县| 上思县| 马尔康县| 临洮县| 南乐县| 翁牛特旗| 富阳市| 宜阳县| 翁源县| 日土县| 类乌齐县| 古田县| 长寿区| 佳木斯市| 马关县| 广西| 深水埗区| 古蔺县| 通道| 丰台区| 凭祥市| 曲松县| 中西区|