Tag: datetime

如何比较两次从NSDate。 在比较时返回ndate。 #debug我的代码

这里是代码: // get current date/time NSDate *today = [NSDate date]; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; // display in 12HR/24HR (ie 11:25PM or 23:25) format according to User Settings [dateFormatter setTimeStyle:NSDateFormatterMediumStyle]; [dateFormatter setDateFormat:@"HH:mm:ss"]; NSString *currentTime = [dateFormatter stringFromDate:today]; currentTime = [currentTime stringByReplacingOccurrencesOfString:@"AM" withString:@""]; currentTime = [currentTime stringByReplacingOccurrencesOfString:@"PM" withString:@""]; currentTime = [currentTime stringByReplacingOccurrencesOfString:@" " withString:@""]; NSDateFormatter […]

ios-ntp框架同步问题

我使用ntp-ios框架从我的ipad应用程序从github下载获取GTM时间,通过使用下面的代码 [NetworkClock sharedNetworkClock]; // // gather up the ntp servers … [NSDate networkDate]; // This will give the network date and time regardless of device date 如果设备时间是错误的,那么我也正在得到正确的gmt时间。 但我的问题是,当应用程序进入后台,我改变了设备的设备时间。 那么之后,如果我再次通过点击它使应用程序活跃,那么它给错误的时间。 如果我退出应用程序并重新启动它,那么它就像预期的那样工作。 请build议如何解决这个问题。 提前致谢 。 。 。

如何从给定的date/时间减去1小时

我想在给定的date/时间前一小时获得date/时间。 假设给定的date/时间是2012-11-25 13:20:35(YYYY-mm-dd小时:分钟:秒)。

如何在ios中获取今天的开始和结束时间?

我通过使用此代码获取当前的date和时间 let today: NSDate = NSDate() let dateFormatter: NSDateFormatter = NSDateFormatter() dateFormatter.timeStyle = NSDateFormatterStyle.MediumStyle dateFormatter.dateFormat = "yyyy-MM-dd hh:mm:ss" dateFormatter.timeZone = NSTimeZone(abbreviation: "SGT"); print(dateFormatter.stringFromDate(today)) 但我想获得今天的开始时间和结束时间 例如: 12-09-2016 00:00:00 AND 12-09-2016 23:59:59 如何获得当前date的开始和结束时间?

问题与date格式使用NSDateFormatter

我有一个datestring,我想要转换为另一种格式。 原始datestring的例子是: “2013-06-04 02:19:21 +0000” 我想将其转换为“星期三,六月四日” NSString * date_string = @"2013-06-04 02:19:21 +0000"; NSDateFormatter *complexdateFormater = [[NSDateFormatter alloc] init]; [complexdateFormater setDateFormat:@"yyyy-M-DD HH:mm:ss Z"]; NSDate* complexdate = [complexdateFormater dateFromString:date_string]; NSString *formatString = [NSDateFormatter dateFormatFromTemplate:@"EE, MMM d" options:0 locale:[NSLocale currentLocale]]; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:formatString]; NSString *todayString = [dateFormatter stringFromDate:complexdate]; 但是对于上述情况的今天的string打印出来:月份作为Jan,而不考虑原始string中的月份值。 我哪里错了?

Swift:将NSDate转换为c#的ticks

我需要将NSDate转换为C#滴答。 DateTime.ticks将date转换为从0001年1月1日开始的刻度。 我怎样才能做到这一点? 提前致谢。

生成NSDateFormatter(null)SQLite和iOS 5.1

也许有人可以帮忙解释为什么我将string转换为date时得到一个空值。 这一切看起来不错,但我显然在这里失去了一些东西。 一些背景: 这个iPad的应用程序将在不同的国家使用,我将需要做一个计算date,看看自用户上次login后90天过去了。 我有一个DateLastIn字段设置为TEXT的SQLite数据库 我的对象有一个DateLastIn属性设置为NSDate 当填充我的logging对象时,我设置了一个NSDateFormatter。 NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"yyyy-MM-dd hh:mm:ss"]; // SQLite default date format 然后我阅读DateLastIn(使用SQLite的FMDB封装)。 // test SQLite as String NSString *testDate = [results stringForColumn:@"DateLastIn"]; NSLog(@"DateLastIn straight from DB (string) shows %@", testDate); 结果: DateLastIn直接从DB(string)显示2012-04-23 18:20:51 一切都很好。 接下来我testing转换这个NSDate对象,例如 NSDate *aDate = [[NSDate alloc] init]; aDate = [formatter dateFromString:testDate]; […]