使用本地时区将unix时间戳转换为NSdate [英] Converting a unix timestamp to NSdate using local timezone

查看:197
本文介绍了使用本地时区将unix时间戳转换为NSdate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以 NSDecimalNumber的形式获得了一些 start_times end_times code>从API请求返回。

I'm getting some start_times and end_times in the form of NSDecimalNumbers back from an API request.

我已成功将这些 NSDecimalNumber 转换为 NSDate s,但代码没有考虑时区。

I have successfully been able to convert these NSDecimalNumbers into NSDates, but the code is not taking time zones into account.

我需要它来使用设备上默认的时区。

I need for it to use the timezone that is default on the device.

推荐答案

这应该用你当前的语言环境做你需要的事情

This should do what you need with current locale

double unixTimeStamp =1304245000;
NSTimeInterval _interval=unixTimeStamp;
NSDate *date = [NSDate dateWithTimeIntervalSince1970:_interval];
NSDateFormatter *formatter= [[NSDateFormatter alloc] init];
[formatter setLocale:[NSLocale currentLocale]];
[formatter setDateFormat:@"dd.MM.yyyy"];
NSString *dateString = [formatter stringFromDate:date];

这篇关于使用本地时区将unix时间戳转换为NSdate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆