nsdate

how do I set an existing NSDate's time?

限于喜欢 提交于 2019-11-28 06:50:29
how do I set an existing NSDate 's time? That is I have a date (say current date/time), but then want to set this to a specific time (e.g. 11.23am) say. What is the quickest way to do this in objective C? I'm looking at NSCalendar and see methods such as dateByAddingComponents:toDate:options: , and dateFromComponents: , but these don't seem to quite hit the mark for what I need here. For example: dateFromComponents: - I would have to work out all components for this to work which seems like overkill dateByAddingComponents:toDate:options: - I don't want to ADD in my case but rather "set" the

Parsing ISO 8601 with NSDateFormatter

混江龙づ霸主 提交于 2019-11-28 06:37:56
问题 I've read through the various posts on SO about this, but have still not solved the problem. Here's the string that I'm trying to parse into an NSDate object: 2012-04-08T12:00:00.00+02:00 I understand that the problem is the time zone format. Here's the date format string that I'm trying: yyyy-MM-dd'T'HH:mm:SSZZZZ Thanks for any help. 回答1: Three things: Use the -[NSDateFormatter getObjectValue:forString:range:error:] method to learn how much of the string was parsed and what error prevented

NSDateComponents weekOfYear returns wrong date

蓝咒 提交于 2019-11-28 06:22:41
问题 so i am making a basic week picker, where you can pick a week number and year, and get the corresponding date from the weeks startpoint. A basic test scenario let calendar = NSCalendar.currentCalendar() let components = NSDateComponents() components.year = 2015 components.weekOfYear = 15 print(calendar.dateFromComponents(components)!) You can see, that i set the wanted year to 2015 and the wanted week to 15, but the result i get is: "2014-12-31 23:00:00 +0000" ... and thats really gets me

Convert a Date (absolute time) to be sent/received across the network as Data in Swift?

醉酒当歌 提交于 2019-11-28 06:20:49
问题 I am looking for a Swifty way to generate a timestamp. My macOS app logs some data and stamps it with the time the data was created. The data will then be sent across the network (as Data ) to be reconstructed on an iPad. Is there any Swift class that will work to generate the timestamp? NSDate? NSTimeIntervalSince1970? CFAbsoluteTimeGetCurrent() The requirements are: Store the timestamp in as few bytes as possible (pref. Int ) Have some semblance to real Earth time (I'd rather not generate

converting timestamp to nsdate format

和自甴很熟 提交于 2019-11-28 06:11:47
I want to convert my timestamp value 1308031456 to NSDate format (which yields the value Tue, 14 Jun 2011 06:04:16 GMT in online web conversion). How would I convert between the two programmatically? OBJ - C: Use dateWithTimeIntervalSince1970: , NSDate *date = [NSDate dateWithTimeIntervalSince1970:timeStamp]; SWIFT: Use init(timeIntervalSince1970:) let date = NSDate(timeIntervalSince1970:timeStamp) You can use the use the method dateWithTimeIntervalSince1970: to convert the timestamp you've which is the epoch time. NSDate * myDate = [NSDate dateWithTimeIntervalSince1970:1308031456]; In obj c

How to send a localNotification at a specific time everyday, even if that time has passed?

主宰稳场 提交于 2019-11-28 06:10:05
问题 I have this code which runs a notification everyday at 7am, it gets the current date and then runs the notification when it gets to the set hour, my problem is if the time has already passed the set run time then everyday it will run at the user current time not my time on 7am, here is my code var dateFire: NSDateComponents = NSDateComponents() var getCurrentYear = dateFire.year var getCurrentMonth = dateFire.month var getCurrentDay = dateFire.day dateFire.year = getCurrentYear dateFire.month

Constructing an NSDate from today's date and a string with the time

天大地大妈咪最大 提交于 2019-11-28 05:48:48
问题 If I have a string representing a time, say "10:45 am", and do the following to parse the string: NSDateFormatter *dateFormat; dateFormat = [[NSDateFormatter alloc] init]; [dateFormat setDateFormat:@"h:mm a"]; NSLog(@"%@", [dateFormat dateFromString:@"10:45 AM"]); I would get this logged: 2013-09-09 17:52:30.416 TimeTest[49491:a0b] 2000-01-01 15:45:00 +0000 How can I create an NSDate for the current day at the given time? I tried this NSDate *date = [NSDate date]; NSDateFormatter *formatter =

How to make a periodic call to a method in objective c?

余生长醉 提交于 2019-11-28 04:42:55
问题 if the question is not explained clearly please excuse me. I'm developing an iphone Client-Server app, i created all the classes, instances and ect. I can even send get and parse the response too.. Anyway, now i need to make my method be called in a defined period of time(for instance, call it repeatly in 10 seconds). I googled a lot and also take a look at NSDate but i couldn't solve.. Now, can anyone please help me how to handle this situation? Thank you very much 回答1: You can create and

How do I get weekday and/or name of month from a NSDate variable?

不羁岁月 提交于 2019-11-28 04:40:33
Alright. The problem we're having is that we have NSStrings filled with dates in the format of yyyyMMdd and what we want to do is to get the current weekday and name of month. The function dagOmvandlare converts the datestring to weekday and month. The function is then called on viewDidload to name all our button-titles from english to swedish months. our current solution is looking like this: -(NSString *)dagOmvandlare:(id) suprDatum{ NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; dateFormatter.dateFormat = @"yyyyMMdd"; NSDate *date = [dateFormatter

Getting the last day of a month

非 Y 不嫁゛ 提交于 2019-11-28 04:28:36
How can I get the last day of the current month as an NSDate ? Jonas Schnelli NSDate *curDate = [NSDate date]; NSCalendar* calendar = [NSCalendar currentCalendar]; NSDateComponents* comps = [calendar components:NSYearCalendarUnit|NSMonthCalendarUnit|NSWeekCalendarUnit|NSWeekdayCalendarUnit fromDate:curDate]; // Get necessary date components // set last of month [comps setMonth:[comps month]+1]; [comps setDay:0]; NSDate *tDateMonth = [calendar dateFromComponents:comps]; NSLog(@"%@", tDateMonth); should also work. // Adapted from running code in my app NSDate *curDate = [NSDate date]; NSCalendar