consider the string like "2017-08-30T06:40:00.000+00:00" 1 - How to convert this string into timestamp 2 - How to group this value into time slots (for eg, if the value is time = 2:30 PM, it will be grouped into the slot of 2pm to 3pm)
Asked
Active
Viewed 336 times
-8
-
what is so wrong about the question? – u7568924 Aug 29 '17 at 06:30
-
show what you have tried – Neha Gupta Aug 29 '17 at 06:31
-
@NehaGupta My question is how to do this? I don't understand, I am getting an array of strings from my backend in the above mentioned format, I have to group them into time slots of 1-1 hour – u7568924 Aug 29 '17 at 06:33
-
It is very simple what have you tried ? – Deepakraj Murugesan Aug 29 '17 at 06:39
-
"yyy-MM-ddThh:mm:ss" @DeepakrajMurugesan – u7568924 Aug 29 '17 at 06:41
-
@Moritz I appreciate your advice, but I have also asked another question of how can dates be grouped in 1 hour gap, People just seem to down vote without reading FULL description. – u7568924 Aug 29 '17 at 08:58
1 Answers
-1
I will help you with an idea in objective C try converting to the swift, If not you can ask me. I will help you out with the right code. Write a function like this generically and use it in the places wherever you wanted to convert the date format.
+ (NSString*)dateFormatConv:(NSString *)givenFormat DateValue:(NSString*)dateString needFormat:(NSString *)reqFormat LabelName:(UILabel *)lbl{
NSString *myDateString = dateString;
NSDateFormatter *DateFormatter=[[NSDateFormatter alloc] init];
[DateFormatter setDateFormat:givenFormat];
NSDate *date = [DateFormatter dateFromString:myDateString];
[DateFormatter setDateFormat:reqFormat];
NSString *dateString2 = [DateFormatter stringFromDate:date];
lbl.text = dateString2;
return dateString2;
}

Deepakraj Murugesan
- 1,195
- 11
- 30
-
I know how the conversion is done, what I am not getting is the "date format" that has to be set. I have tried setting "yyy-MM-ddThh:mm:ssZZZ" also – u7568924 Aug 29 '17 at 06:50
-
1is not `"yyy-MM-ddThh:mm:ssZZZ"`it is `yyyy-MM-dd'T'hh:mm:ss.SSS'Z'` – Anbu.Karthik Aug 29 '17 at 06:50
-
-
I agree with @Anbu.Karthik. It is correct format yyyy-MM-dd'T'hh:mm:ss.SSS'Z' – Deepakraj Murugesan Aug 29 '17 at 06:59
-