gpt4 book ai didi

iphone - iOS相差2倍

转载 作者:行者123 更新时间:2023-11-28 23:10:32 24 4
gpt4 key购买 nike

这就是这里的情况。我在时代有当前时间。我也有天数。我想找出两者之间的区别,以纪元格式给出一些过去的时间。即

currentEpochTime - (x days) to give some past time in epoch format.

这是我到目前为止得到的 -

+ (double)currTimeInEpoch
{
NSDate *todayDate = [NSDate date];
double ti = [todayDate timeIntervalSince1970]*1000;
return ti;
}

+ (NSString *)timeDiff:(double)epoch diff:(double)diffInDays
{
double past = epoch - (diffInDays * 24 * 60 * 60 * 1000);
return [[NSNumber numberWithDouble:past] stringValue];
}

我做的对吗?不确定。有没有更简单的方法来做到这一点?

最佳答案

一个人去很危险。拿着这个。

NSDateComponents *dateComponents = [[NSDateComponents alloc] init];
dateComponents.day = -40; // Number of days to subtract
NSDate *newDate = [[NSCalendar autoupdatingCurrentCalendar] dateByAddingComponents:dateComponents toDate:[NSDate date] options:0];
NSTimeInterval newDateInEpochTime = [newDate timeIntervalSince1970] * 1000;

关于iphone - iOS相差2倍,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8404740/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com