2016-12-15 3 views
0
NSDate *now = [NSDate date]; 
    NSCalendar *calendar = [NSCalendar currentCalendar]; 
    // find next date where the minutes are zero 
    NSDate *nextHour = [calendar nextDateAfterDate:now matchingUnit:NSCalendarUnitMinute value:0 options:NSCalendarMatchNextTime]; 
    // get the number of seconds between now and next hour 
    NSDateComponents *componentsToNextHour = [calendar components:NSCalendarUnitSecond fromDate:now toDate:nextHour options:0]; 
    //NSLog(@"%ld", componentsToNextHour.second); 
    NSString *dec = [NSString stringWithFormat:@"%ld", (long)componentsToNextHour.second]; 

上記のコードでは、現在の日付と時刻を秒単位に変換していますが、これらの秒数をunixtimestampに変換することはできません。これについての考え方は高く評価されます。秒をUnixTimeStampに変換する方法は?

答えて

1

ご質問が分かりません。あなたは次の時間が始まるUnixタイムスタンプを求めている場合は、次の操作を行います。

NSDate *now = [NSDate date]; 
    NSCalendar *calendar = [NSCalendar currentCalendar]; 
    // find next date where the minutes are zero 
    NSDate *nextHour = [calendar nextDateAfterDate:now matchingUnit:NSCalendarUnitMinute value:0 options:NSCalendarMatchNextTime]; 
    time_t unixTimestampAtWhichNextHourStarts = (time_t)nextHour.timeIntervalSince1970; 
    NSLog(@"ts=%ld", (long)unixTimestampAtWhichNextHourStarts); 
+0

は優秀なので、私は最初、秒に変換ファンタスティック、非常に認め、あなたは時間の私の多くを保存する必要がいけない、私はでしたそれに時間を詰め込んだ。 –

関連する問題