自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

iOS開發(fā)之時(shí)間設(shè)置和格式輸出

移動(dòng)開發(fā) iOS
本文為大家介紹了iOS開發(fā)中的時(shí)間設(shè)置和格式輸出等內(nèi)容,程序源碼直接分享給大家,希望對(duì)51CTO的各位網(wǎng)友有所幫助,如果有什么意見歡迎交流。

NSDate

NSCalendar

NSDateFormatter

  1.    NSDate *now=[NSDate date]; 
  2.   NSCalendar *cal=[[NSCalendar alloc] 
  3.                    initWithCalendarIdentifier:NSGregorianCalendar 
  4.                    ]; 
  5.   [cal setTimeZone:[NSTimeZone systemTimeZone]]; // 3 
  6.   NSDateComponents *dc = [cal components:(NSHourCalendarUnit|NSMinuteCalendarUnit| 
  7.                                                NSSecondCalendarUnit) fromDate:now];  // 4 
  8.   //now  2013-06-13 05:45:43 +0000 
  9.     NSLog(@"The time is%@",now); 
  10.   NSLog(@"The time is%d:%d:%d",[dc hour], [dc minute], [dc second]); // 5 
  11.   NSDateFormatter *dateFormatter=[[NSDateFormatter alloc]init]; 
  12.   [dateFormatter setAMSymbol:(@"AM")]; 
  13.   [dateFormatter setPMSymbol:@"PM"]; 
  14.  // [dateFormatter setDateFormat:@"yyyy-MM-dd"]; 
  15. [dateFormatter setDateFormat:@"dd/MM/yyyy hh:mmaaa"]; 
  16.    
  17.   NSDate *curDate=[NSDate date]; 
  18.   NSString *str=[dateFormatter stringFromDate :curDate]; 
  19.   NSLog(@"%@",str); 
  20.   NSCalendar *c=[NSCalendar currentCalendar]; 
  21.   unsigned int unitFlags=NSYearCalendarUnit|NSMonthCalendarUnit| 
  22.   NSDayCalendarUnit|NSHourCalendarUnit|NSMinuteCalendarUnit|NSSecondCalendarUnit; 
  23.   NSDateComponents *dd=[c components:unitFlags fromDate:curDate]; 
  24.   int y=[dd year]; 
  25.   int d=[dd day]; 
  26.   NSLog(@"%d 年 %d日",y,d); 

 

責(zé)任編輯:閆佳明 來(lái)源: apkbus
相關(guān)推薦

2018-06-06 10:14:32

Kafka時(shí)間輪任務(wù)

2013-07-29 04:37:53

iOS開發(fā)iOS開發(fā)學(xué)習(xí)NSLog輸出格式

2017-10-20 12:13:11

數(shù)據(jù)庫(kù)PostgreSQL時(shí)間戳

2009-07-31 13:52:32

C#時(shí)間函數(shù)C#時(shí)間格式

2021-02-20 09:36:11

數(shù)據(jù)大數(shù)據(jù)數(shù)據(jù)可視化

2024-12-13 09:42:38

javascripmatch方法

2021-06-24 14:41:16

鴻蒙HarmonyOS應(yīng)用

2013-07-29 11:34:46

iOS開發(fā)iOS開發(fā)學(xué)習(xí)設(shè)置UITextVie

2014-02-19 09:51:29

iOS開發(fā)時(shí)間處理

2011-07-08 18:34:34

iOS Debug Release

2016-08-04 11:11:08

PythonMatplotlib繪圖

2010-05-21 09:10:56

Visual Stud

2013-07-24 18:22:02

iOS開發(fā)學(xué)習(xí)iOS開源框架和類

2023-09-06 12:49:31

系統(tǒng)Ubuntu

2024-01-08 22:03:22

python代碼開發(fā)

2014-03-06 10:50:59

iOS開發(fā)

2013-07-25 13:35:14

iOS開發(fā)學(xué)習(xí)UIScrollVietouchesBega

2013-07-29 05:01:31

iOS開發(fā)iOS開發(fā)學(xué)習(xí)按鈕拖動(dòng)和點(diǎn)擊

2013-07-25 14:04:11

iOS開發(fā)學(xué)習(xí)UITableView

2010-07-16 15:44:57

Perl格式化輸出
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)