gpt4 book ai didi

iphone - ios - 获取今天上午 10 点

转载 作者:行者123 更新时间:2023-11-29 04:14:14 24 4
gpt4 key购买 nike

如何在 ios 中获取今天上午 10 点和明天上午 10 点?

NSDateComponents *nowComponents = [calendar components:NSYearCalendarUnit | NSWeekCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit fromDate:today];

[nowComponents setHour:10];

这没有给出正确的回应。我该怎么做?

最佳答案

尝试一下这段代码,希望它能起作用。如果您想获取明天的上午 10 点,请将时间设置为 34

NSDate *date = [NSDate date];
NSTimeZone *gmt = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier: NSGregorianCalendar];
[gregorian setTimeZone:gmt];
NSDateComponents *components = [gregorian components: NSUIntegerMax fromDate: date];
[components setHour: 10];
[components setMinute:0];
[components setSecond: 0];
NSDate *newDate = [gregorian dateFromComponents: components];
NSLog(@"Date%@", newDate);
[gregorian release];

关于iphone - ios - 获取今天上午 10 点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13932054/

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