• 获取当前的系统时间 年-月-日 小时-分钟-秒


    获取当前的系统时间 年-月-日 小时-分钟-秒

    代码如下:

    NSDate * newDate = [NSDate date];

    //实例化一个NSDateFormatter对象

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

    //设定时间格式,这里可以设置成自己需要的格式

    [dateformat setDateFormat:@"yyyy-MM-dd HH:mm:ss"];

    NSString * newDateOne = [dateformat stringFromDate:newDate];

    [dateformat setFormatterBehavior:NSDateFormatterFullStyle];

    //将本地时间转换成指定时区时间

    [dateformat setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]];

    NSLog(@"%@",newDateOne);

    //alloc  别忘了释放内存

    [dateformat release];

    /----------------------------------------------------------------------------------/

    大写的H日期格式将默认为24小时制,

    小写的h日期格式将默认为12小时

    不需要特别设置,只需要在dataFormat里设置类似"yyyy-MMM-dd"这样的格式就可以了

    日期格式如下:

    y 年 Year 1996; 96

    M 年中的月份 Month July; Jul; 07

    w 年中的周数 Number 27

    W 月份中的周数 Number 2

    D 年中的天数 Number 189

    d 月份中的天数 Number 10

    F 月份中的星期 Number 2

    E 星期中的天数 Text Tuesday; Tue

    a Am/pm 标记 Text PM

    H 一天中的小时数(0-23) Number 0

    k 一天中的小时数(1-24) Number 24

    K am/pm 中的小时数(0-11) Number 0

    h am/pm 中的小时数(1-12) Number 12

    m 小时中的分钟数 Number 30

    s 分钟中的秒数 Number 55

    S 毫秒数 Number 978

    z 时区 General time zone Pacific Standard Time; PST; GMT-08:00

    Z 时区 RFC 822 time zone -0800

  • 相关阅读:
    Heapsort 堆排序算法详解(Java实现)
    GIve Me A Welcome Hug!
    linux系统救援模式拯救mv libc.so.6文件后无法使用命令的悲剧
    RabbitMQ集群部署
    使用Xshell通过堡垒机登录服务器
    dubbo + zookeeper环境部署
    zookeeper集群部署
    zabbix-3.0.1 添加微信报警
    zabbix-3.0.1结合grafana绘图
    Centos7.2安装zabbix3.0.1简要
  • 原文地址:https://www.cnblogs.com/gaoxiao228/p/2483556.html
Copyright © 2020-2023  润新知