hi am using following to convert date to string in objective C.
-(void)convertDateToJsonString:(NSString *)strDate
{
NSDateFormatter * formatter = [[NSDateFormatter alloc] init];
[formatter setTimeZone:[NSTimeZone systemTimeZone]];
[formatter setLocale:[NSLocale systemLocale]];
[formatter setDateFormat:@"yyyy/MM/dd"];
NSDate * date =[formatter dateFromString:strDate];
long long milliseconds = (long long)([date timeIntervalSince1970] * 1000.0);
NSLog(@"After conversion %lli",milliseconds);
}
its giving date but always getting time is 00:00:00 something not current time.How to get selected date with current time in milli second.
but its working for current date like below
long long millisecs = (long long)([[NSDate date] timeIntervalSince1970] * 1000.0);
NSLog(@"After conversion %lli",millisecs);
Am getting from date picker date and converting.
And also for getting exact time zone like +530 in ios is there any methods? i know [NSTimezone Systemzone] but its giving whole value like "Asia/kolkatta +..."
The problem is that your
strDate
is not getting parsed bydateFromString:
. The result is that yourdate
will benil
andtimeInternvalSince1970
will do some default processing onnil
. You can confirm this by adding:after your initialize
date
. The assertion will fail.The solution is that you need a better
formatter
- one that is consistent with the format of the passed instrDate
.But, perhaps you have a more fundamental problem. The
UIDatePicker
date
property returns anNSDate
object directly. Where are you getting yourstrDate
from?