• 根据数字对应星期几


    第一种:

    NSString *week  = @“2”

    NSString *Weekday =  [self passWeek:week];

     

    + (NSString *)passWeek:(NSString *)week {

        if ([week containsString:@"1"]) {

            week = [week stringByReplacingOccurrencesOfString: @"1" withString:@"周一"];

        }    else if ([week containsString:@"2"]) {

            week = [week stringByReplacingOccurrencesOfString:@"2" withString:@"周二"];

        }  else  if ([week containsString:@"3"]) {

            week = [week stringByReplacingOccurrencesOfString:@"3" withString:@"周三"];

        }   else  if ([week containsString:@"4"]) {

            week = [week stringByReplacingOccurrencesOfString:@"4" withString:@"周四"];

        }  else if ([week containsString:@"5"]) {

            week = [week stringByReplacingOccurrencesOfString:@"5" withString:@"周五"];

        }   else  if ([week containsString:@"6"]) {

            week = [week stringByReplacingOccurrencesOfString:@"6" withString:@"周六"];

        }   else if ([week containsString:@"7"]) {

            week = [week stringByReplacingOccurrencesOfString:@"7" withString:@"周日"];

        }

        return week;

    }

     

    第二种:

    NSString *week  = @“2,3,4”

    NSString *Weekday =  [self passWeek:week];

     

    + (NSString *)passWeek:(NSString *)week {

        if ([week containsString:@"1"]) {

            week = [week stringByReplacingOccurrencesOfString: @"1" withString:@"周一"];

        }  

       if ([week containsString:@"2"]) {

            week = [week stringByReplacingOccurrencesOfString:@"2" withString:@"周二"];

        }

       if ([week containsString:@"3"]) {

            week = [week stringByReplacingOccurrencesOfString:@"3" withString:@"周三"];

        }  

       if ([week containsString:@"4"]) {

            week = [week stringByReplacingOccurrencesOfString:@"4" withString:@"周四"];

        }

       if ([week containsString:@"5"]) {

            week = [week stringByReplacingOccurrencesOfString:@"5" withString:@"周五"];

        }  

        if ([week containsString:@"6"]) {

            week = [week stringByReplacingOccurrencesOfString:@"6" withString:@"周六"];

        }  

        if ([week containsString:@"7"]) {

            week = [week stringByReplacingOccurrencesOfString:@"7" withString:@"周日"];

        }

        return week;

    }

  • 相关阅读:
    设计模式中的多态——策略模式详解
    Spring IOC容器启动流程源码解析(一)——容器概念详解及源码初探
    并发包下常见的同步工具类详解(CountDownLatch,CyclicBarrier,Semaphore)
    HNOI2020游记
    旧年之末,新年伊始
    退役V次后做题记录
    PKUWC2020 游记
    CSP2019退役记
    CTS/APIO2019游记
    HNOI2019游记
  • 原文地址:https://www.cnblogs.com/chenzq12/p/6213676.html
Copyright © 2020-2023  润新知