【代码笔记】iOS-两个时间字符串的比较
一,效果图。
二,代码。

- - (void)viewDidLoad
- {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- [self initTimerCompare];
- }
- #pragma -mark -functions
- //比较时间
- -(void)initTimerCompare
- {
- NSString *starTimer=@"2014-08-29";
- NSString *finishTimer=@"2014-09-30";
- BOOL result = [starTimer compare:finishTimer] == NSOrderedSame;
- NSLog(@"result:%d",result);
- if (result==1) {
- UIAlertView *alert=[[UIAlertView alloc]initWithTitle:nil message:@"开始时间和结束时间相等" delegate:self cancelButtonTitle:@"知道了" otherButtonTitles:nil, nil];
- [alert show];
- return;
- }
- BOOL result1 = [starTimer compare:finishTimer]==NSOrderedDescending;
- NSLog(@"result1:%d",result1);
- if (result1==1) {
- UIAlertView *alert=[[UIAlertView alloc]initWithTitle:nil message:@"开始时间晚于结束时间" delegate:self cancelButtonTitle:@"知道了" otherButtonTitles:nil, nil];
- [alert show];
- return;
- }
- BOOL result2 = [starTimer compare:finishTimer]==NSOrderedAscending;
- NSLog(@"result2:%d",result1);
- if (result2==1) {
- UIAlertView *alert=[[UIAlertView alloc]initWithTitle:nil message:@"开始时间早于结束时间" delegate:self cancelButtonTitle:@"知道了" otherButtonTitles:nil, nil];
- [alert show];
- return;
- }
- }

【代码笔记】iOS-两个时间字符串的比较的更多相关文章
- 苹果浏览器和ios中,时间字符串转换问题
背景:在开发PC端项目和小程序时,遇到过一个时间字符串转化问题,在苹果浏览器和ios微信客户端里,"2018-10-15 18:20" 以 字符"-"拼接的时间 ...
- 【代码笔记】iOS-和当前时间比较
代码: #import "RootViewController.h" @interface RootViewController () @end @implementation R ...
- 【代码笔记】iOS-提醒时间的选择
一,效果图. 二,工程图. 三,代码. RootViewController.h #import <UIKit/UIKit.h> @interface RootViewController ...
- 【代码笔记】iOS-产生随机字符串
一,代码: - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, ...
- 微坑---微信小程序ios上时间字符串转换为时间戳时,在开发工具上和安卓手机上运行成功
给定一个时间字符串 var time="2017-02-27 16:42:53" js有三种转换为时间戳的方法:1.var timestamp = Date.parse(time ...
- 微信小程序ios上时间字符串转换为时间戳时会报错,在开发工具上和安卓手机上运行成功
给定一个时间字符串 var time="2017-02-27 16:42:53" js有三种转换为时间戳的方法: 1.var timestamp = Date.parse(tim ...
- iOS开发笔记-两种单例模式的写法
iOS开发笔记-两种单例模式的写法 单例模式是开发中最常用的写法之一,iOS的单例模式有两种官方写法,如下: 不使用GCD #import "ServiceManager.h" ...
- 在PHP代码中处理JSON 格式的字符串的两种方法:
总结: 在PHP代码中处理JSON 格式的字符串的两种方法: 方法一: $json= '[{"id":"1","name":"\u ...
- iOS 时间戳和时间互换,计算两日期相隔天数
/* *获取当前系统时间的时间戳 */ +(NSInteger)getNowTimestamp; /** * 获取当前时间 */ + (NSString *)getNowTimeTampF ...
随机推荐
- JavaScript的setTimeout和setInterval的深入理解
发表过一片博客<跟着我用JavaScript写计时器>,比较基础.....有网友说应该写一下setTimeout的原理和机制,嗯,今天就来写一下吧: 直奔主题:setTimeout和set ...
- Linux - 修复Ubuntu错误“System program problem detected”
The error "System program problem detected" comes up when a certain application crashes. U ...
- LeetCode - 207. Course Schedule
207. Course Schedule Problem's Link ---------------------------------------------------------------- ...
- 使用jquery的append(content)方法的注意事项
append(content)函数:向每个匹配的元素内部追加内容. 如以下示例: 向所有段落中追加一些HTML标记. HTML 代码: <p>I would like to say: &l ...
- 关于EF的 序列化类型为“XXX”的对象时检测到循环引用。
在用Ef的时候,也许经常会遇到循环引用的错误. 下面提供解决办法.(不是Json.Net,如果是Json.Net可以给导航属性通过增加特性标签来解决该问题) ef大多数问题,可以通过ToList()来 ...
- android布局属性详解
RelativeLayout用到的一些重要的属性: 第一类:属性值为true或false android:layout_centerHrizontal 水平居中 android:layout_cen ...
- Bootstrap学习笔记系列3-------Bootstrap简单表单显示
表单布局 垂直或基本表单 基本的表单结构时BootStrap自带的,创建基本表单的步骤如下: 向父<form>元素添加role = "form": 为了获取最佳的间距, ...
- ASP.NET MVC 请求流程:Route
1.RouteTable RouteTable翻译过来的意思就是路由表,一个Web应用程序具有一个全局的路由表,该路由表通过System.Web.Routiing.RouteTable的静态只读属性R ...
- C# AD(Active Directory)域信息同步,组织单位、用户等信息查询
示例准备 打开上一篇文章配置好的AD域控制器 开始菜单-->管理工具-->Active Directory 用户和计算机 新建组织单位和用户 新建层次关系如下: 知识了解 我们要用C# ...
- Support for multiple result sets
https://blueprints.launchpad.net/myconnpy/+spec/sp-multi-resultsets Calling a stored procedure can p ...