简体   繁体   English

将设备日期和时间转换为PST TimeZone

[英]Convert Device date and time to PST TimeZone

As my title say that i need to convert my iPhone device date and time to PST timezone ? 如我的标题所述,我需要将iPhone设备的日期和时间转换为PST时区?

I got NSDate in NSString formate from server as PST Timezone , so i need to convert my current device time to PST Timezone . 我从服务器的NSString formate中获得了NSDate作为PST时区 ,因此我需要将当前设备时间转换为PST时区

In my apps. 在我的应用中。 i need to set minimum and maximum time of UIDatePicker such like 我需要设置UIDatePicker的最小和最大时间,例如

minimum time = current time ; 最短时间=当前时间; maximum time = Date (string formate) which i got it from server. 最长时间=日期(字符串formate) ,它是从服务器获取的。

I use following code 我使用以下代码

NSString *dateString = [[self.listOfDomains objectAtIndex:indexPath.row] objectForKey:@"ends_at"]; // got from Server 
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSDate *maxDate = [[NSDate alloc] init];
    maxDate = [dateFormatter dateFromString:dateString];

    NSCalendar *calMax = [NSCalendar currentCalendar];
    NSDateComponents *pstCompoMax = [calMax components: NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit fromDate: maxDate];
    pstCompoMax.timeZone = [NSTimeZone timeZoneWithName: @"PST"];
    NSDate *pstMaxDate = [calMax dateFromComponents: pstCompoMax];

And use it in datePicker 并在datePicker中使用

[self.datePicker setMinimumDate:pstMinDate];
[self.datePicker setMaximumDate:pstMaxDate];

But i can not able to set minimum and maximum date in datePicker. 但是我不能在datePicker中设置最小和最大日期。 But if i only set minimum/maximum date of datePicker then it works.. 但是,如果我只设置datePicker的最小/最大日期,则它可以工作。

For solve my issue, i'm trying about 2 hour but i can not find any solution. 为了解决我的问题,我正在尝试大约2个小时,但找不到任何解决方案。

For Your Info : I'm using Xcode 5 and i need do it in iOS version 5 to Latter (iOS 7) 为您的信息:我正在使用Xcode 5,我需要在iOS版本5中更新为Latter(iOS 7)

Please help me on this issue, 请帮我解决这个问题,

Thanks in advance. 提前致谢。

The issue seems like setting of NSTimeZone. 该问题似乎是NSTimeZone的设置。 Could you please try setting the timezone in datepicker like that below:- 您可以尝试在datepicker中设置时区,如下所示:-

datePicker.timeZone = [NSTimeZone timeZoneWithName: @"PST"];

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM