简体   繁体   English

将 UNIX 时间戳转换为日期、小时、分钟、秒

[英]Converting UNIX timestamp into date, hours, minutes, seconds

在 Objective-C 中,如何将 UNIX 时间戳(即表示时间戳的数字形式)转换为日期、时间(小时、分钟、秒)?

For output, use an NSDateFormatter .对于输出,使用NSDateFormatter To extract values for other purposes, use NSDateComponents .要为其他目的提取值,请使用NSDateComponents eg:例如:

NSDate *date = [NSDate dateWithTimeIntervalSince1970:1234567];
NSDateComponents *weekdayComponents = [[NSCalendar currentCalendar] components:NSWeekdayCalendarUnit fromDate:date];
int weekday = [weekdayComponents weekday];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从Iphone上的Objective C中的UNIX时间戳获取日,月,年,小时,分钟,秒 - How to get day, month, year, hours, minutes, seconds from a UNIX timestamp in Objective C on Iphone 小时分钟秒到秒 - hours minutes seconds to seconds ios Unix时间戳到数小时前 - unix timestamp to hours ago 显示计时器,从日期开始计算天数,小时数,分钟数和秒数,然后实时递增 - Display timer that works out Days, hours, minutes and seconds from a date then increments in real time 以天,小时,分钟和秒显示差异,然后实时更新? - display the difference in Days, Hours, Minutes and Seconds with it then updating in realtime? 使用本地时区将unix时间戳转换为NSdate - Converting a unix timestamp to NSdate using local timezone 如何使用NSDateFormatter只获得小时和分钟的完整时间戳? - How to get full timestamp with only passing hours and minutes with NSDateFormatter? 将日期转换为 Unix 时间(自 1970 年以来的秒数) - Convert date to Unix time (seconds since 1970) iPhone Datepicker.date快4小时56分钟,有帮助吗? - iPhone Datepicker.date is 4 hours and 56 minutes fast, help? 如何在iPhone上将NSTimeInterval分解为年,月,日,小时,分钟和秒? - How do I break down an NSTimeInterval into year, months, days, hours, minutes and seconds on iPhone?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM