ios项目有关的系统 uuid,系统版本号,手机型号,获取当前时间……

本文提供了一款iOS应用中关键功能的实现教程:如何将时间戳转换为可读时间格式,以及如何获取应用版本号。通过使用Objective-C语言,我们展示了从时间戳到日期字符串的转换过程,并介绍了如何从应用的`info.plist`文件中获取版本号信息。同时,文章还介绍了获取系统唯一标识UUID和操作系统版本号的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.获取系统当前时间

 -(NSString *)getTimeNow

{

    NSString* date;

    NSDateFormatter * formatter = [[NSDateFormatter alloc ] init];

    [formatter setDateFormat:@"YYYY-MM-dd hh:mm:ss:SSS"];

    date = [formatter stringFromDate:[NSDate date]];

    NSString *timeNow = [[NSString alloc] initWithFormat:@"%@", date];

    return timeNow;

}

有时候当我们开发做项目的时候,后台的数据会传过来时间的数据是时间戳的格式,我们应该要将这个时间戳转化为时间格式

+(NSString *)timeHelpWithTime:(NSString *)timeStr  //timeStr為时间戳 返回的数据就是正常的时间格式

{

    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];

    [formatter setDateStyle:NSDateFormatterMediumStyle];

    [formatter setTimeStyle:NSDateFormatterShortStyle];

    [formatter setDateFormat:@"YYYY.MM.dd HH:mm:ss"];

    NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:[timeStr integerValue]];

    return [formatter stringFromDate:confromTimesp];

}


2.获取App的版本号 取plist里面的

NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];

 NSString *version = [infoDictionary objectForKey:@"CFBundleVersion"];


3.获取系统唯一标示 uuid

NSString *uuid = [[NSBundle mainBundle] bundleIdentifier];


4.获取手机操作系统版本号  如:7.0   6.1   7.1.1  

NSString *os = [[UIDevice currentDevice] systemVersion];



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值