【代码笔记】iOS-两个时间字符串的比较

时间:2023-01-10 17:15:00

一,效果图。

【代码笔记】iOS-两个时间字符串的比较

二,代码。

【代码笔记】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-两个时间字符串的比较的更多相关文章

  1. 苹果浏览器和ios中,时间字符串转换问题

    背景:在开发PC端项目和小程序时,遇到过一个时间字符串转化问题,在苹果浏览器和ios微信客户端里,"2018-10-15 18:20" 以 字符"-"拼接的时间 ...

  2. 【代码笔记】iOS-和当前时间比较

    代码: #import "RootViewController.h" @interface RootViewController () @end @implementation R ...

  3. 【代码笔记】iOS-提醒时间的选择

    一,效果图. 二,工程图. 三,代码. RootViewController.h #import <UIKit/UIKit.h> @interface RootViewController ...

  4. 【代码笔记】iOS-产生随机字符串

    一,代码: - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, ...

  5. 微坑---微信小程序ios上时间字符串转换为时间戳时,在开发工具上和安卓手机上运行成功

    给定一个时间字符串  var time="2017-02-27 16:42:53" js有三种转换为时间戳的方法:1.var timestamp = Date.parse(time ...

  6. 微信小程序ios上时间字符串转换为时间戳时会报错,在开发工具上和安卓手机上运行成功

    给定一个时间字符串  var time="2017-02-27 16:42:53" js有三种转换为时间戳的方法: 1.var timestamp = Date.parse(tim ...

  7. iOS开发笔记-两种单例模式的写法

    iOS开发笔记-两种单例模式的写法   单例模式是开发中最常用的写法之一,iOS的单例模式有两种官方写法,如下: 不使用GCD #import "ServiceManager.h" ...

  8. 在PHP代码中处理JSON 格式的字符串的两种方法:

    总结: 在PHP代码中处理JSON 格式的字符串的两种方法: 方法一: $json= '[{"id":"1","name":"\u ...

  9. iOS 时间戳和时间互换&comma;计算两日期相隔天数

    /*  *获取当前系统时间的时间戳  */ +(NSInteger)getNowTimestamp;   /**  * 获取当前时间  */ + (NSString *)getNowTimeTampF ...

随机推荐

  1. 找出数组中最长的连续数字序列&lpar;JavaScript实现&rpar;

    原始题目: 给定一个无序的整数序列, 找最长的连续数字序列. 例如: 给定[100, 4, 200, 1, 3, 2], 最长的连续数字序列是[1, 2, 3, 4]. 小菜给出的解法: functi ...

  2. 数论 - 高精度Fibonacci数 --- UVa 10183 &colon; How Many Fibs &quest;

    How many Fibs? Description Recall the definition of the Fibonacci numbers: f1 := 1 f2 := 2 fn := f n ...

  3. 用imageNamed加载图片产生的问题

    通常我们会用imageNamed:来加载图片,但是用这个API有个问题,就是它会缓存加载的image. 因此,对于那些被重用的图片,这个API很高效.但是对于那些使用很少的图片,用这个就很耗内存,那怎 ...

  4. Auto Layout 在iOS屏幕适配中的使用

    前几天在做iOS屏幕的适配,也就是让同样的UI控件的布局在不同屏幕的iOS设备上面都正确显示,storyBoard就无可避免的用到了Auto Layout.在这个过程中,我发现要熟练掌握Auto La ...

  5. myeclipse&sol;eclipse添加Spket插件实现ExtJs4&period;2&sol;ExtJs3智能提示

    前言 感谢luotao,本博客是copy这篇博客的:http://www.cnblogs.com/luotaoyeah/p/3803926.html ,因为太重要了,所以笔者再写一次. 重要说明:ec ...

  6. Codeforces Round &num;207 &lpar;Div&period; 2&rpar;

    A:超级大水题: 代码: #include<cstdio> #define maxn 105 using namespace std; int n,a[maxn],x,y,ans; int ...

  7. 在现代渲染API下,封装跨平台渲染框架的尝试 - 资源管理

    小生资历浅薄,不讨论该主题的重要性与未来的意义,只是个人兴趣爱好平日对这个问题思考了很多,总觉得要写点东西记录下来.框架还没有定型,只是记录自己设计的过程. 系统要跨平台,首先得将平台相关的实现与平台 ...

  8. Cadence OrCAD Cpature创建Title Block

    为了统一部门设计文档的管理,需要对文档命名.设计文件符号.设计文件规范做出规定.这里介绍下Cadence OrCAD Cpature原理图设计中创建满足自己的Title Block. 1.创建库文件 ...

  9. 【Python54&period;1--豆瓣登录】

    1.模拟豆瓣登录 ''' |-- 代码解析: |-- 1.登录必须具备的条件:url,cookie,fromData fromData的参数如下: source: index_nav form_ema ...

  10. 如何将frm格式MYD格式MYI格式文件导入MySQL中

    frm,myd,myi是属于MySQL存储数据的文件,phpMyAdmin是无法导入的. phpMyAdmin支持的文件格式为sql文件. 其实很简单: 1.找到你的mysql的安装目录下的data文 ...