nsdate

NSDateComponents to NSDate - Swift

ぐ巨炮叔叔 提交于 2021-02-18 21:09:19
问题 I have this function : private func getCurrentDateComponent() -> NSDateComponents { let date = NSDate() let calendar = NSCalendar.currentCalendar() let components = calendar.components(.CalendarUnitHour | .CalendarUnitMinute | .CalendarUnitMonth | .CalendarUnitYear | .CalendarUnitDay, fromDate: date) return components } When I call it and I use the function date var d = this.getCurrentDateComponent().date I don't know why the variable d is nil... Thank you for your help Ysee 回答1: That's how I

Date formatter for a certain format of date

你离开我真会死。 提交于 2021-02-08 07:33:51
问题 I might missing something, but I can't compose proper date formatter string for the date: 2016-01-14T10:24:26+0000 What is 'T' here? and how to include timezone? My string does not work: @"yyyy-MM-dd'T'hh:mm:ss Z" 回答1: You have to use 'T' in single quotes like below format to retrive string ftom date: yyyy-MM-dd'T'hh:mm:ssZ Let me know. 回答2: NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init]; dateFormatter.dateFormat = @"yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'"; NSDate *yourDate =

Get difference between two dates?

前提是你 提交于 2021-02-05 12:13:11
问题 I have two dates in 24 hours formate like (dd-MMM-yyyy HH:mm). I want to get a difference between these two dates. My Code : This is getting only dates, I want a number of days and remaining time in hours also. (like 6days 5 hours) NSTimeInterval secondsBetween = [date2 timeIntervalSinceDate:date1]; int numberOfDays = secondsBetween / 86400; NSLog(@"There are %d days in between the two dates.", numberOfDays); 回答1: NSDateComponentsFormatter can do that NSTimeInterval secondsBetween = [date2

How to change nsstring to nsdate format in iphone?

半腔热情 提交于 2021-01-28 01:04:06
问题 I have struggling with to convert nsstring to nsdate format. I have a date in nsstring format like (2011-08-25 18:30:00 +0000), but i want to change it in nsdate format (08/26/2011). How to change it? Can any one help me please? Thanks in advance... I have spend one day to solve this but i cant find out the solution.. Please help me friends.... This is my code, NSString *dateString = @"2011-08-25 18:30:00 +0000"; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter

How to check consecutive weekdays in an array

百般思念 提交于 2021-01-27 15:58:47
问题 I have a function below (datesCheck) that cycles through an array of dates and firstly removes any entries if there is more than one a day and then checks whether the dates are consecutive within the array, returning the number of consecutive days from the current date. func datesCheck(_ dateArray: [Date]) -> Int { let calendar = Calendar.current let uniqueDates = NSSet(array: dateArray.map { calendar.startOfDay(for: $0) }).sorted { ($0 as AnyObject).timeIntervalSince1970 > ($1 as AnyObject)

How to add th and st in Date Format

独自空忆成欢 提交于 2021-01-27 07:35:50
问题 I want to convert the date like "Friday 17th, 7:00pm" this format. but I am unable to add "th" and "st" after the date. I am using below code to convert the date format like this. please tell me. What I do for this format? func convertDateFormater(_ date: String) -> String { let dateFormatter = DateFormatter() dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"//this your string date format dateFormatter.timeZone = NSTimeZone(name: "UTC") as TimeZone? //dateFormatter.locale = Locale

How to get the Current Date in ReactNative?

你。 提交于 2021-01-20 18:54:50
问题 I am building my first ReactNative iOS and Android app. I am an iOS coder with Swift and Obj-C. How do I fetch the current date using ReactNative. Shall I use Native Modules or is there an ReactNative API from which I can get this data ? 回答1: The JavaScript runtime in React Native has access to date information just like any other environment. As such, simply: new Date() ... will give you the current date. Here's the MDN on working with dates in JS. If you want a good JS library to make

How to get the Current Date in ReactNative?

我怕爱的太早我们不能终老 提交于 2021-01-20 18:51:08
问题 I am building my first ReactNative iOS and Android app. I am an iOS coder with Swift and Obj-C. How do I fetch the current date using ReactNative. Shall I use Native Modules or is there an ReactNative API from which I can get this data ? 回答1: The JavaScript runtime in React Native has access to date information just like any other environment. As such, simply: new Date() ... will give you the current date. Here's the MDN on working with dates in JS. If you want a good JS library to make

How to get the Current Date in ReactNative?

女生的网名这么多〃 提交于 2021-01-20 18:50:34
问题 I am building my first ReactNative iOS and Android app. I am an iOS coder with Swift and Obj-C. How do I fetch the current date using ReactNative. Shall I use Native Modules or is there an ReactNative API from which I can get this data ? 回答1: The JavaScript runtime in React Native has access to date information just like any other environment. As such, simply: new Date() ... will give you the current date. Here's the MDN on working with dates in JS. If you want a good JS library to make

Convert time string into date swift

折月煮酒 提交于 2020-08-07 05:22:28
问题 I am using firebase as a backend and storing a string of time like this 7:00 PM. I am trying to convert the string received from Firebase and convert it into NSDate so I can sort it, change the time..etc I've looked online and come up with this code so far dateFormatter.dateFormat = "hh:mm a" dateFormatter.locale = NSLocale.current dateFormatter.timeZone = NSTimeZone.local let date = dateFormatter.date(from: item) self.times.append(date!) print("Start: \(date)") where item is the string (7:00