zoukankan      html  css  js  c++  java
  • nsdate 设置固定值

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

        NSString *dateString = @"2000-01-01";

        [dateFormatter setDateFormat:@"yyyy-MM-dd"];//setDateFormat必须一致

       

        [self dataFromString:dateString withFormat:@"yyyy-MM-dd"];

    - (void)dataFromString:(NSString*)dateStr withFormat:(NSString*)format{

        

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

        [formater1 setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]];//消除时差8小时

        [formater1 setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]];//date返回不为空

        [formater1 setDateFormat:format];

        NSDate *date1 = [formater1 dateFromString:dateStr];

        NSLog(@"date1======%@",date1);

        }

  • 相关阅读:
    break return continue
    爬虫---请求
    pycharm加开头注释
    爬虫---入门
    pip
    XML基础
    英语
    布局
    adobe
    StackOverflow
  • 原文地址:https://www.cnblogs.com/liuting-1204/p/6566230.html
Copyright © 2011-2022 走看看