//获取当前时间
02    NSDate *now = [NSDate date];
03    NSLog(@”now date is: %@”, now);
04
05    NSCalendar *calendar = [NSCalendar currentCalendar];
06    NSUInteger unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
07    NSDateComponents *dateComponent = [calendar components:unitFlags fromDate:now];
08     
09    int year = [dateComponent year];
10    int month = [dateComponent month];
11    int day = [dateComponent day];
12    int hour = [dateComponent hour];
13    int minute = [dateComponent minute];
14    int second = [dateComponent second];
15
16    NSLog(@”year is: %d”, year);
17    NSLog(@”month is: %d”, month);
18    NSLog(@”day is: %d”, day);
19    NSLog(@”hour is: %d”, hour);
20    NSLog(@”minute is: %d”, minute);
21    NSLog(@”second is: %d”, second);

iOS-获取当前时间的年、月、日、时、分、秒的更多相关文章

  1. [Windows]获取当前时间(年/月/日/时/分/秒)

    struct tm* GetCurTime(time_t inTime) { struct tm* curTime = localtime(&inTime); curTime->tm_y ...

  2. oracle截取时间的年/月/日/时/分/秒

    修改日期格式为年月日时分秒: alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';select to_char(sysdate,'yyy ...

  3. C#WinForm中显示实时时间:年/月/日 时/分/秒 星期X

    //加载窗体时 string weekstr = ""; private void Form22_Load(object sender, EventArgs e) { this.t ...

  4. ASP.NET C# 获取当前日期 时间 年 月 日 时 分 秒

    我们可以通过使用DataTime这个类来获取当前的时间.通过调用类中的各种方法我们可以获取不同的时间:如:日期(2008-09-04).时间(12:12:12).日期+时间(2008-09-04 12 ...

  5. ASP.NET C# 日期 时间 年 月 日 时 分 秒 格式及转换(转自happymagic的专栏)

    在平时编码中,经常要把日期转换成各种各样的形式输出或保持,今天专门做了个测试,发现DateTime的ToString()方法居然有这么多的表现形式,和大家一起分享. DateTime time=Dat ...

  6. ASP.NET 日期 时间 年 月 日 时 分 秒 格式及转换

    在平时编码中,经常要把日期转换成各种各样的形式输出或保持,今天专门做了个测试,发现DateTime的ToString()方法居然有这么多的表现形式,和大家一起分享. DateTime time=Dat ...

  7. mysql 获取系统时间的下一天 年-月-日 时:分:秒

    DAY) as date

  8. Java 获取年 月 日 时 分 秒

    /** * 英文简写(默认)如:2010-12-01 */ public static String FORMAT_SHORT = "yyyy-MM-dd"; /** * 英文全称 ...

  9. js将当前时间格式化为年-月-日 时:分:秒

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  10. Js 日期字符串分别截取 年 月 日 时 分 秒

    function shijiantime(times){ var timearr = times.replace(" ", ":").replace(/\:/g ...

随机推荐

  1. UDP template 代码

    服务端 from socket import * import json,struct client= socket(AF_INET,SOCK_STREAM) client.connect(('127 ...

  2. PYTHON-文件指针的移动,移动和函数基础

    # 文件内指针的移动 #大前提:文件内指针的移动是Bytes为单位的,唯独t模式下的read读取内容个数是以字符为单位 # f.seek(指针移动的字节数,模式控制): 控制文件指针的移动# 模式控制 ...

  3. PYTHON-面向对象 继承 派生

    1. 什么是继承 继承是一种新建类的方式,新建的类称之为子类/派生类,被继承的类称之为父类/基类/超类 继承有3个特点: 1. 子类可以遗传/重用父类的属性(解决类与类之间代码冗余的问题) 2. 在p ...

  4. app中页面滑动,防止a链接误触

    问题 app中list列表,当我们用手滑动屏幕,屏幕上页面内容会快速滚动,不会因为手已经离开了屏幕而滚动停止,突然手触摸暂停,当手指是在a标签上面时,会跳转链接,这对客户体验及其不好 思路 先判断滚动 ...

  5. CF 449D 题解(状压+容斥)

    状压妙啊... 本题的主体思路:状压+容斥原理(或状压+数位dp) 记g[i]表示按位与后结果所有位上至少有i个1的方案数 那么根据容斥原理,ans=g[0]-g[1]+g[2]-g[3]+g[4]. ...

  6. WCF客户端从服务器下载数据

    1.打开VS选择控制台项目新建一个解决方案Server,然后添加两个类库Contract和Service. 2.在Contract中添加一个接口IFileDownload using System; ...

  7. 192 Word Frequency

    Write a bash script to calculate the frequency of each word in a text file words.txt. For simplicity ...

  8. 微信WebView关闭后本地cookie无法清除问题

    问题背景 在微信WebView下的页面中登录后,关闭WebView返回后再次进入页面,发现登录态还存在,原因是微信不会主动清除cookie以及其他的缓存. 期望是关闭窗口后会清除cookie,重新进入 ...

  9. python全栈开发day33-进程间的通信、进程间的数据共享,进程池

    一.昨日内容回顾: 1.  守护进程 1).p.saemon, 2 ).p.terminate 3 ).p.join 2.  同步控制 1).锁,Lock 互斥锁,解决数据安全.进程之间资源抢占问题. ...

  10. TNS:listener does not currently know of service requested in connect descriptor错误改正

    (SID_LIST = (SID_DESC =  (SID_NAME = PLSExtProc)  (ORACLE_HOME = E:\oracle\product\10.2.0\db_1)  (PR ...