//获取当前时间日期星期
- (NSString *)getCurrentTimeAndWeekDay { NSArray * arrWeek=[NSArray arrayWithObjects:@"星期日",@"星期一",@"星期二",@"星期三",@"星期四",@"星期五",@"星期六", nil];
NSDate *date = [NSDate date];
/*
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
*/
//ios 8.0 之后 不想看见警告用下面这个
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
NSDateComponents *comps = [[NSDateComponents alloc] init];
/*
NSInteger unitFlags = NSYearCalendarUnit |
NSMonthCalendarUnit |
NSDayCalendarUnit |
NSWeekdayCalendarUnit |
NSHourCalendarUnit |
NSMinuteCalendarUnit |
NSSecondCalendarUnit;
*/
//ios 8.0 之后 不想看见警告用下面这个
NSInteger unitFlags = NSCalendarUnitYear |NSCalendarUnitMonth | NSCalendarUnitDay |NSCalendarUnitWeekday | NSCalendarUnitHour |NSCalendarUnitMinute |NSCalendarUnitSecond;
comps = [calendar components:unitFlags fromDate:date];
int week = [comps weekday];
int year=[comps year];
int month = [comps month];
int day = [comps day];
return [NSString stringWithFormat:@"%d-%d-%d %@",year,month,day,[arrWeek objectAtIndex:week]];
}

iOS - 获取当前时间日期星期几的更多相关文章

  1. Swift3.0 iOS获取当前时间 - 年月日时分秒星期

    Swift3.0 iOS获取当前时间 - 年月日时分秒星期func getTimes() -> [Int] { var timers: [Int] = [] // 返回的数组 let calen ...

  2. 获取当前时间日期并格式化--JS

    工作当中,总是遇到很多觉得不错的JS脚本.现在觉得还是找个地方记录下来,以后可以随时查看. /** *获取当前时间日期并格式化 */ function getNowDate(){ var mydate ...

  3. iOS 获取当前时间格式化字符串

    iOS 获取当前时间格式化字符串 太阳火神的漂亮人生 (http://blog.csdn.net/opengl_es) 本文遵循"署名-非商业用途-保持一致"创作公用协议 转载请保 ...

  4. iOS之获取当前时间日期并按固定格式显示

    写一个常用的获取当前日期,时间的代码.并且能以规定的格式显示出来 1 2 3 4 5 NSDate *currentDate = [NSDate date];//获取当前时间,日期 NSDateFor ...

  5. iOS - 获取系统时间年月日,阳历(公历)日期转农历的方法

    //获取当前时间 NSDate *now = [NSDate date]; NSLog(@" now date is: %@ ",now); NSCalendar *calenda ...

  6. iOS获取网络时间与转换格式

      [NSDate date]可以获取系统时间,但是会造成一个问题,用户可以自己修改手机系统时间,所以有时候需要用网络时间而不用系统时间.获取网络标准时间的方法: 1.先在需要的地方实现下面的代码,创 ...

  7. iOS 获取当前时间以及计算年龄(时间差)

    获取当前时间 NSDate *now = [NSDate date]; NSLog(@"now date is: %@", now); NSCalendar *calendar = ...

  8. iOS获取本地时间

    NSDate *currentDate = [NSDate date];//获取当前时间,日期 NSDateFormatter *dateFormatter = [[NSDateFormatter a ...

  9. ios获取系统时间

    //获取系统时间 NSDate * date=[NSDate date]; NSDateFormatter *dateformatter=[[NSDateFormatter alloc] init]; ...

随机推荐

  1. Java精通并发-Lock锁机制深入详解

    从这次开始接触Java1.5推出的并发包中的东东,先看一下jdk中的并发包: 接下来咱们则会集中对这些并发包中的核心进行深入了解,不光要学会怎么用这些并发包中的类,而且还得知道这些功能背后运行的原理, ...

  2. Python线程join和setDaemon

    看一下线程的setDaemon()方法 import time import threading import ctypes import inspect def sayHello(): for i ...

  3. 关于__int 128 的读入与输出

    inline __int128 read() { ,w=; ; while(!isdigit(ch)) {w|=ch=='-';ch=getchar();} )+(X<<)+(ch^),c ...

  4. 项目Alpha冲刺(团队)-博客汇总

    格式描述 课程名称:软件工程1916|W(福州大学) 作业要求:项目Alpha冲刺(团队) 团队名称:为了交项目干杯 作业目标:集中记录所有敏捷冲刺日志的集合 团队信息 队员学号 队员姓名 个人博客地 ...

  5. JQuery系列(6) - jQuery设计思想

    jQuery是目前使用最广泛的javascript函数库. 据统计,全世界排名前100万的网站,有46%使用jQuery,远远超过其他库.微软公司甚至把jQuery作为他们的官方库. JQuery设计 ...

  6. 命令查询windows&Linux系统版本信息

    Linux 查询系统名字输入"cat /proc/version",说明正在运行的内核版本uname -rwindows 查询系统名字win+r -> winversyste ...

  7. rune 数据类型

    // rune is an alias for int32 and is equivalent to int32 in all ways. It is // used, by convention, ...

  8. LeetCode 886. Possible Bipartition

    原题链接在这里:https://leetcode.com/problems/possible-bipartition/ 题目: Given a set of N people (numbered 1, ...

  9. A1016 | 磨人的大模拟

    这题写得头晕……明天我再评价 #include <stdio.h> #include <memory.h> #include <math.h> #include & ...

  10. luogu P1550 [USACO08OCT]打井Watering Hole

    题目背景 John的农场缺水了!!! 题目描述 Farmer John has decided to bring water to his N (1 <= N <= 300) pastur ...