zoukankan      html  css  js  c++  java
  • NSDate

    #pragma mark dateCreate

    void dateCreate(){

    NSDate  *date=[NSDate date];//调用当前时间 now

    image

    //返回以当前时间为基准,然后过了secs秒时间。

    date=[NSDate  dateWithTimeIntervalSinceNow:10];//TimeInterval 是秒

    //会比当前时间快10s

    //基准为1970-1-1 00:00:00 然后过了secs秒时间

    date=[NSDate  dateWithTimeIntervalSince1970:10];

    //随机返回一个未来的时间

    date=[NSDate distanceFuture];

    //随机返回以前的某个时间

    date=[NSDate distancePast];

    NSLog(@”%@”,date);

    }

    #pragme mark 取回时间间隔

    void dateUse(){

    NSDate  *date=[NSDate date];

    //返回1970走过的毫秒数

    NSTimeInterval interval = [date timeIntervalSince1970];

    //跟其他时间进行对比

    NSDate date1=[NSDate dateWithTimeIntervalSinceNow:20];

    [date timeIntervalSinceDate:date1];

    //日期比较

    NSDate *early=[date earlierDate:date1];//返回比较早的时间

    NSDate *late=[date laterDate:date1];//返回比较晚的时间

    image

    }


    void dateFormat(){

    NSDate *date=[NSdate date];

    //2015-6-4 22:48:45

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

    //HH是24进制,hh是12进制

    formatter.dateFormat=@”yyyy-MM-dd HH:mm:ss”;

    //设置时区

    formatter.locale=[[[NSLocale alloc]WithLocaleIdentinitifier:@”zh_CN“]autorelease];

    NSString *str=[formatter stringFromDate:date]; //date->string

    NSlog(@”%@”,string);

    //返回的是格林治时间

    NSDate *date2=[formatter dateFromString:@“2015-6-4 22:51:34”];

    NSLog(@”%@”,date2);

    [formatter release];

    //NSCalendor

    }

  • 相关阅读:
    python操作csv,对比两个csv文件某列值
    监控端口和僵尸进程脚本
    openldap创建只读账号
    shell 判断文件内容是否改变
    golang调用shell命令标准输出阻塞管道
    fexpect 源码
    python pexpect 免交互自动恢复gitlab数据
    consul client agent 本地读取key value
    pip 安装三方库报超时
    微信小程序滚动tab的实现
  • 原文地址:https://www.cnblogs.com/yesihoang/p/4553343.html
Copyright © 2011-2022 走看看