获取当前时间分开的年,月,日
来源:互联网 发布:一对一辅导软件免费 编辑:程序博客网 时间:2024/05/17 03:02
CurDay);
NSCalendar *calendar = [NSCalendarcurrentCalendar];
NSRange range = [calendarrangeOfUnit:NSDayCalendarUnitinUnit:NSMonthCalendarUnitforDate:[NSDatedate]];
NSUInteger numberOfDaysInMonth = range.length;
numberOfDaysInMonth 即为当月的天数。更多用法查看NSCalendar, NSDateComponents帮助文档
2. 获取当前年份和月份和天数
NSCalendar *calendar = [NSCalendar currentCalendar];
unsigned unitFlags = NSCalendarUnitYear | NSCalendarUnitMonth|NSCalendarUnitDay;
NSDateComponents *components = [calendar components:unitFlags fromDate:[NSDate date]];
NSInteger iCurYear = [components year]; //当前的年份
NSInteger iCurMonth = [components month]; //当前的月份
NSInteger iCurDay = [components day]; // 当前的号
//截取字符串
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
//设定时间格式,这里可以设置成自己需要的格式
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm"];
NSString *currentDateStr = [dateFormatter stringFromDate:LHTimeView.datePicker.date];
NSString *yearStr = [currentDateStr substringWithRange:NSMakeRange(0, 4)];
NSString *monthStr = [currentDateStr substringWithRange:NSMakeRange(5, 2)];
NSString *dayStr = [currentDateStr substringWithRange:NSMakeRange(8, 2)];
NSString *hourStr = [currentDateStr substringWithRange:NSMakeRange(11, 2)];
NSString *minuteStr = [currentDateStr substringWithRange:NSMakeRange(14, 2)];
NSString *birStr = [NSString stringWithFormat:@"%@%@%@%@%@%@%@%@%@%@",yearStr,@"年",monthStr,@"月",dayStr,@"日",hourStr,@"时",minuteStr,@"分"];
- 获取当前时间分开的年,月,日
- 获取当前时间的年、月、日、时、分、秒
- 获取当前时间的年、月、日、时、分、秒
- javascript获取当前时间(年-月-日 时:分:秒)
- JS_获取当前时间(2017年06月27日)
- UIDatePicke获取当前时间的年、月、日、时、分、秒, //显示成中文格式的
- 获取当前系统时间的年、月、日、小时、分、秒
- iOS-获取当前时间的年、月、日、时、分、秒
- iOS-获取当前时间的年、月、日、时、分、秒
- ios-通过NSCalendar来获取当前时间的年、月、日、时、分、秒
- ios 获取当前的系统时间 年-月-日 小时-分钟-秒
- iOS-获取当前时间的年、月、日、时、分、秒
- 为了记录下iOS-获取当前时间的年、月、日、时、分、秒
- iOS8-获取当前时间的年、月、日、时、分、秒
- iOS-获取当前时间的年、月、日、时、分、秒
- iOS-获取当前时间的年、月、日、时、分、秒
- 用js获取当前的时间包括年、月、日、时、分、秒
- 用js获取当前的时间包括年、月、日、时、分、秒
- iframe内容自适应高度并兼容所有浏览器的最有效直接的方法
- 如何为Github Pages设置动态的背景图片?
- FileReader 和 FileWriter
- 网络编程socket
- 一位acm过来人的经验
- 获取当前时间分开的年,月,日
- Android实现APP在线下载更新
- spring mvc的优点,原理,设计思想,特点,相关参数
- mybatis数据库配置问题
- 常用的字符编码
- XML 简介
- 自己动手,难以足食
- Android 面试精华题目总结
- springcloud学习笔记二:服务提供、消费与ribbon