nsdate

Adjust NSDate by one hour for DST

折月煮酒 提交于 2020-01-13 14:03:51
问题 My app uses a feed from localendar.com to create a tableview of upcoming events. The issue though, is that the feeds from localendar do not account for DST, so they end up showing the pubDate of the feed as 1 hour later than the event actually starts. My app parses the feed and takes the date into the detail line in the cell, which makes it confusing. I am trying to get my app to detect whether or not the user is in DST, and if they are, subtract one hour from the date. However, when I use

converting date to correct format

て烟熏妆下的殇ゞ 提交于 2020-01-11 11:54:07
问题 I've a webservice which gives back my date in the following way. Wed Oct 31 11:59:44 +0000 2012 But I want it to give it back in this way 31-10-2012 11:59 I know that it should be done with a NSDateFormatter. But I don't now how to implement it in the correct way. I've something like this. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init]; [dateFormatter setDateFormat:@"dd/MM/yyyy"]; [dateFormatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"GMT+0:00"]]; NSDate *date =

NSDate format issue

天涯浪子 提交于 2020-01-11 07:49:09
问题 Here is the code from the nsdate formatter... for some reason the value dateSelected is incorrect... instead of "April 30 2011 7:55PM" it returns 2011-05-01 02:55... any idea what am i doing wrong? NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init]; [outputFormatter setDateFormat:@"h:mm a"]; objEventInsert.eventtime = [outputFormatter stringFromDate:self.datePicker.date]; NSLog(@"%@",objEventInsert.eventtime); NSDateFormatter *dateForm = [[NSDateFormatter alloc] init];

How can I get the actual date and time if the device date and time are inaccurate?

◇◆丶佛笑我妖孽 提交于 2020-01-11 05:00:10
问题 I noticed that if I set my device time manually, and turn off the automatic time sync on my iOS device, [NSDate date] returns the date and time assuming the device time is correct--which it may not be. Since the docs mention that NSDate has some sort of sync with NTP, I am wondering if there is any built-in way to get the accurate date and time instead of having to assume the device date and time is correct. 回答1: Perhaps https://github.com/jbenet/ios-ntp can help you? It's a library that can

Convert NSString to NSDate [duplicate]

倾然丶 夕夏残阳落幕 提交于 2020-01-11 03:24:06
问题 This question already has answers here : Closed 6 years ago . Possible Duplicate: Converting NSString to NSDate (and back again) I make a request to the flickr api and it returns me the date in the following format "2013-02-01T06:25:47Z" How do i convert this into NSDate format?? 回答1: It's a simple one, converting NSString to NSDate we use NSDateformatter using dateFromString method. We need to provide the Dateformatter style with existing style for NSString NSDateFormatter *dateFormatter = [

NSDateFormatter, am I doing something wrong or is this a bug?

北城以北 提交于 2020-01-09 02:15:08
问题 I'm trying to print out the date in a certain format: NSDate *today = [[NSDate alloc] init]; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"yyyyMMddHHmmss"]; NSString *dateStr = [dateFormatter stringFromDate:today]; If the iPhone is set to 24 hour time, this works fine, if on the other hand the user has set it to 24 hour time, then back to AM/PM (it works fine until you toggle this setting) then it appends the AM/PM on the end even though I

Get UTC time and local time from NSDate object

China☆狼群 提交于 2020-01-08 19:44:29
问题 In objective-c, the following code results in the UTC date time information using the date API. NSDate *currentUTCDate = [NSDate date] In Swift however, let date = NSDate.date() results in local date and time. I have two questions: How can I get UTC time and local time (well date gives local time) in NSDate objects. How can I get precision for seconds from the NSDate object. EDIT 1: Thanks for all the inputs but I am not looking for NSDateFormatter objects or string values. I am simply

All dates between two Date objects (Swift)

情到浓时终转凉″ 提交于 2020-01-08 12:30:27
问题 I’m creating a date using NSDateComponents() . let startDate = NSDateComponents() startDate.year = 2015 startDate.month = 9 startDate.day = 1 let calendar = NSCalendar.currentCalendar() let startDateNSDate = calendar.dateFromComponents(startDate)! ... now I want to print all dates since the startDate until today, NSDate() . I’ve already tried playing with NSCalendarUnit , but it only outputs the whole difference, not the single dates between. let unit: NSCalendarUnit = [.Year, .Month, .Day,

All dates between two Date objects (Swift)

て烟熏妆下的殇ゞ 提交于 2020-01-08 12:30:20
问题 I’m creating a date using NSDateComponents() . let startDate = NSDateComponents() startDate.year = 2015 startDate.month = 9 startDate.day = 1 let calendar = NSCalendar.currentCalendar() let startDateNSDate = calendar.dateFromComponents(startDate)! ... now I want to print all dates since the startDate until today, NSDate() . I’ve already tried playing with NSCalendarUnit , but it only outputs the whole difference, not the single dates between. let unit: NSCalendarUnit = [.Year, .Month, .Day,

Calculate time interval to 0.00 of the next day according to GMT in swift or objective-c?

為{幸葍}努か 提交于 2020-01-07 09:44:27
问题 I tried something like this: var calendar = Calendar.current var dayFutureComponents = DateComponents() dayFutureComponents.day = 1 // aka 1 day var d = calendar.date(byAdding: dayFutureComponents, to: Date()) ...//setting of d.hour, d.minute, d.second to zero and finding the difference between 2 dates The problem is for example my current GMT is +3 . So the result differs from one I need to achieve by 3 hours. How to fix this issue? 回答1: First create a Calendar for the UTC timezone. Second