My CMMotionActivity object has the property timestamp and startDate.
Printing both of these shows the value is from 1970, not 2016 as expected.
[self.motionActivityManager startActivityUpdatesToQueue:[NSOperationQueue mainQueue] withHandler:^(CMMotionActivity *activity) {
NSLog(#"startDate = %#",activity.startDate);
NSLog(#"timestamp = %f",activity.timestamp);
}];
2016-07-20 17:46:53.294 MyApp[292:30246] timestamp = 8648.852289
2016-07-20 17:46:54.229 MyApp[292:30246] startDate = 1970-01-01 02:24:09 +0000
My device's time and date is set correctly, though it has been turned off for weeks.
EDIT: Today I got this: No code changes.
2016-07-21 11:26:34.292 MyApp[229:7473] startDate = 2016-07-21 10:26:34 +0000
2016-07-21 11:26:34.293 MyApp[229:7473] timestamp = 662.524030
Eh... Close enough. "timestamp" (from NSLogItem) is a NSTimeInterval so a phone running time or something.
I guess 24hrs or a phone reboot fixes the issue.
Related
Hi I have multiple dates which I am comparing with current date. But it is not working. I have done coding but nothing is working for me. I am using comparison same like this link.
Here is what I am doing
let todayDate = Date()
let date1FromServer = //its Date from server which is 2020-02-01 09:00:00 +0000
let date2FromServer = //its Date from server which is 2020-02-02 09:00:00 +0000
let date3FromServer = //its Date from server which is 2020-02-03 09:00:00 +0000
now here I am comparing All three date in simple if else
if(date1FromServer < todayDate){
//Do something for date 1
}else if (date2FromServer < todayDate){
//Do something for date 3
}else if (date3FromServer < todayDate){
// Do something for date 3
}
Case: Now I have date1 and Date 2 is working but date3 is not working. I am saying this because the date3 is exactly on 3 feb 2020
with 9:00 am which is smaller then today date which is 3 feb 2020 with
11:00 am , but it looks like that it is dealing like date 3 is equal
or greater then today date.
When I print date 3 it prints (2020-02-03 06:32:22 +0000) and here the time is wrong, as right now on my device it si 11:32 am but it showing 06: 32 . I think as I am just printing it in log so there could be problem of time zone, but on above code it is also not working.
Please let me know what is the problem here.
Note: I want to compare the Date and time as well.....
If your server date has GMT as time zone then you can adjust your local date to GMT by using offsets
let offsetDate = Date(timeIntervalSince1970:
todayDate.timeIntervalSince1970 + Double(TimeZone.current.secondsFromGMT(for: todayDate)))
and then use offsetDate instead when doing the comparison
In my application i request certain date field from my server, the server returns values like :2014-06-03 00:00:00 EEST , but i need to load that data using GMT(GMT+2…) format, i am using the following code :
double unixTimeStamp = [[date objectAtIndex:indexPath.row] doubleValue];
NSTimeInterval _interval=unixTimeStamp;
NSDate *dateToFinal = [NSDate dateWithTimeIntervalSince1970:_interval];
NSDateFormatter *_formatter=[[NSDateFormatter alloc]init];
_formatter.dateFormat = #"yyyy-MMMM-dd HH:mm:ss zzz";
[_formatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:[[NSUserDefaults standardUserDefaults] objectForKey:#"timeZone"]] ];
[_formatter setDateFormat:#"dd MMMM yyyy"];
dateFinal=[_formatter stringFromDate:dateToFinal];
// NSLog(#"Date Time < 3 %#" , dateFinal);
the user has the possibility to change his timezone, that's why when he saves it it's stored in a local cached variable , which i call in the previous code. But the most weird part is , if the user changes to GMT +1 or +2 or whatever, the application would still output the same hour time, which is 00:00, but if he changes to anything different from GMT, it will change. It's not normal to have GMT,GMT+1,GMT+4… to output the same hour which is 00:00. As a unix timestamp example we have 1401742800, which if u use an online time converter you would get Mon, 02 Jun 2014 21:00:00 GMT , but in the app its neither the same date nor time…what am i missing ?
I'm trying to get systemTimeZone, but it gives me wrong data:
NSTimeZone * currentDateTimeZone = [NSTimeZone systemTimeZone];
NSString* name = [currentDateTimeZone name];
int myGMT = (int)roundf([currentDateTimeZone secondsFromGMT]/60.f/60.f);
I'm living in Budapest,Hungary. It's in GMT+1, but I'm getting myGMT = 2.
But name is ok : name = Europe/Budapest
Why?
The current GMT offset for the Europe/Budapest timezone is GMT+2, because
the Daylight Saving Time started at Sunday, 30 March 2014, and the clocks were
advanced by one hour (see http://www.timeanddate.com/worldclock/city.html?n=50).
You can verify that with
BOOL isDst = [currentDateTimeZone isDaylightSavingTime];
// --> YES
NSTimeInterval dstOffset = [currentDateTimeZone daylightSavingTimeOffset];
// --> 3600
If necessary, you can compute
[currentDateTimeZone secondsFromGMT] - [currentDateTimeZone daylightSavingTimeOffset]
to get the "default" GMT offset for your timezone.
My Problem, in my app i used to show event for each week (week starts with monday), on next button i will be calculating next week dates, my working was working fine , but for a specific day it not returning proper value ,
following is my code
with current week end date , i will add one day to it to get next week start date
NSDateComponents *dateComponet = [[NSDateComponents alloc] init];
[dateComponet setDay:days];
return [[self getCustomCalendar] dateByAddingComponents:dateComponet toDate:date options:0];
where [self getCustomeCalendar] is,
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
[gregorian setLocale:[NSLocale currentLocale]];
[gregorian setFirstWeekday:2]; // 2 monday
return gregorian;
following are the return value for some weeks,
weekend Date: 2014-02-23 00:00:00 +0000 , next weekStartDate : 2014-02-24 00:00:00 +0000
weekend Date: 2014-03-02 00:00:00 +0000 , next weekStartDate : 2014-03-03 00:00:00 +0000
weekend Date: 2014-03-09 00:00:00 +0000 , next weekStartDate : 2014-03-10 00:00:00 +0000
weekend Date: 2014-03-16 00:00:00 +0000 , next weekStartDate : 2014-03-17 00:00:00 +0000
weekend Date: 2014-03-23 00:00:00 +0000 , next weekStartDate : 2014-03-24 00:00:00 +0000
// this is the problem one
weekend Date: 2014-03-30 00:00:00 +0000 , next weekStartDate : 2014-03-30 23:00:00 +0000
as you can see all dates are returning properly by adding one day,
but for 2014-03-30 , when +1 day is added, it should return 2014-03-31 instead, it is returned with 23 hours, i couldn't able to find the cause for this issue
any idea why this is happening ?
Okay even though i couldn't resolve the daylight saving issue, i was able to solve my problem by calculation like below,
Usually i will take the calculated value as week start date, but now what am doing is i will calculate the week start date (current week endDate + 1 ), then will do another calculation to find out what the actual start date for that particular week using NSCalendar (with GMT) which resolves this problem, thanks for the comments and suggestions,
if someone finds better solution, please post it.
I'm not a programmer. I just needed to get some calendar info out of my iphone backup. I got the data out into a SQL Lite database but the dates are in a number format that I don't understand and I can't find a way to convert them to a format I can read. Can someone show me how to convert the numbers or it might be easier to just convert them for me. The numbers are:
352425600
353718000
356054400
357350400
358560000
359769600
Thanks
I wonder if these are in epoch time? try using this calculator and see if the results look possible to you.
EDIT:
nevermind, this answer has what you are looking for.
These numbers are stores as a time difference in seconds to the date 1. January 2001 GMT. You can calculate the date by adding the numbers to this date if you treat them as seconds.
If you can use Objective-C you can use the method: dateWithTimeIntervalSinceReferenceDate
Here is a short loop for calculating the dates:
NSArray *dates = #[#352425600, #353718000, #356054400, #357350400, #358560000, #359769600];
for (NSNumber *timeInterval in dates) {
NSDate *date = [NSDate dateWithTimeIntervalSinceReferenceDate:[timeInterval integerValue]];
NSLog(#"timeInterval:%# = date:%# ", timeInterval, date);
}
And here is the result:
timeInterval:352425600 = date:2012-03-03 00:00:00 +0000
timeInterval:353718000 = date:2012-03-17 23:00:00 +0000
timeInterval:356054400 = date:2012-04-14 00:00:00 +0000
timeInterval:357350400 = date:2012-04-29 00:00:00 +0000
timeInterval:358560000 = date:2012-05-13 00:00:00 +0000
timeInterval:359769600 = date:2012-05-27 00:00:00 +0000