• <tfoot id='DFqk6'></tfoot>

    <small id='DFqk6'></small><noframes id='DFqk6'>

      1. <i id='DFqk6'><tr id='DFqk6'><dt id='DFqk6'><q id='DFqk6'><span id='DFqk6'><b id='DFqk6'><form id='DFqk6'><ins id='DFqk6'></ins><ul id='DFqk6'></ul><sub id='DFqk6'></sub></form><legend id='DFqk6'></legend><bdo id='DFqk6'><pre id='DFqk6'><center id='DFqk6'></center></pre></bdo></b><th id='DFqk6'></th></span></q></dt></tr></i><div id='DFqk6'><tfoot id='DFqk6'></tfoot><dl id='DFqk6'><fieldset id='DFqk6'></fieldset></dl></div>
      2. <legend id='DFqk6'><style id='DFqk6'><dir id='DFqk6'><q id='DFqk6'></q></dir></style></legend>
          <bdo id='DFqk6'></bdo><ul id='DFqk6'></ul>

        NSDateFormatter 和时区问题?

        时间:2023-05-19

        <tfoot id='GeWWU'></tfoot>

        <small id='GeWWU'></small><noframes id='GeWWU'>

          <i id='GeWWU'><tr id='GeWWU'><dt id='GeWWU'><q id='GeWWU'><span id='GeWWU'><b id='GeWWU'><form id='GeWWU'><ins id='GeWWU'></ins><ul id='GeWWU'></ul><sub id='GeWWU'></sub></form><legend id='GeWWU'></legend><bdo id='GeWWU'><pre id='GeWWU'><center id='GeWWU'></center></pre></bdo></b><th id='GeWWU'></th></span></q></dt></tr></i><div id='GeWWU'><tfoot id='GeWWU'></tfoot><dl id='GeWWU'><fieldset id='GeWWU'></fieldset></dl></div>

          <legend id='GeWWU'><style id='GeWWU'><dir id='GeWWU'><q id='GeWWU'></q></dir></style></legend>

                <bdo id='GeWWU'></bdo><ul id='GeWWU'></ul>
                    <tbody id='GeWWU'></tbody>
                  本文介绍了NSDateFormatter 和时区问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我有一个带有 GMT 时间的字符串,我想根据系统时区制作它,但它不能正常工作 -

                  I have a string with time in GMT and i want to make it according to the system time zone but its not working properly -

                  NSLog(@"Time Str = %@",Time);
                  
                  NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
                  [dateFormat setDateFormat:@"dd-MM-yyyy hh:mm a"];
                  
                  [NSTimeZone resetSystemTimeZone];
                  
                  NSLog(@"system time zone = %@",[NSTimeZone systemTimeZone]);
                  
                  [dateFormat setTimeZone:[NSTimeZone systemTimeZone]];
                  
                  NSDate *date = [dateFormat dateFromString:Time];
                  
                  [dateFormat setTimeZone:[NSTimeZone systemTimeZone]];
                  NSLog(@"date from string = %@",date);
                  NSLog(@"string from date = %@",[dateFormat stringFromDate:date]);
                  

                  控制台输出 -

                  ///////////////////////////////////////////////////////////////////////////////

                  ////////////////////////////////////////////////////////////////////////////////////////////////

                  时间 Str = 09-12-2011 07:57 AM

                  Time Str = 09-12-2011 07:57 AM

                  系统时区 = 亚洲/加尔各答 (IST) 偏移量 19800

                  system time zone = Asia/Calcutta (IST) offset 19800

                  字符串中的日期 = 2011-12-09 02:27:00 +0000

                  date from string = 2011-12-09 02:27:00 +0000

                  日期字符串 = 09-12-2011 07:57 AM

                  string from date = 09-12-2011 07:57 AM

                  ///////////////////////////////////////////////////////////////////////////////

                  ////////////////////////////////////////////////////////////////////////////////////////////////

                  加尔各答距格林威治标准时间 +5:30,因此日期时间应为 1:27,但显示为 02:27.此外,当我从该日期获取一个字符串时,它向我显示了我用来制作日期的相同字符串,我希望根据系统时区更新字符串.

                  Calcutta is +5:30 from GMT, so the time in date should be 1:27 but its showing 02:27. Also when i take a string from this date its showing me the same sting that i used to make date, i want the string updated according system time zone.

                  谢谢

                  推荐答案

                  如果日期字符串是 GMT,则不能使用系统时区从 NSString 创建 NSDate.

                  If the date string is in GMT you can't use your system Timezone to create the NSDate from the NSString.

                  替换第一次出现的[dateFormat setTimeZone:[NSTimeZone systemTimeZone]];

                  with [dateFormat setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]];

                  这篇关于NSDateFormatter 和时区问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:将 UTC 日期格式转换为本地 nsdate 下一篇:如何在 iPhone 模拟器中更改时间和时区?

                  相关文章

                  <legend id='Irwdf'><style id='Irwdf'><dir id='Irwdf'><q id='Irwdf'></q></dir></style></legend>

                  <small id='Irwdf'></small><noframes id='Irwdf'>

                  1. <i id='Irwdf'><tr id='Irwdf'><dt id='Irwdf'><q id='Irwdf'><span id='Irwdf'><b id='Irwdf'><form id='Irwdf'><ins id='Irwdf'></ins><ul id='Irwdf'></ul><sub id='Irwdf'></sub></form><legend id='Irwdf'></legend><bdo id='Irwdf'><pre id='Irwdf'><center id='Irwdf'></center></pre></bdo></b><th id='Irwdf'></th></span></q></dt></tr></i><div id='Irwdf'><tfoot id='Irwdf'></tfoot><dl id='Irwdf'><fieldset id='Irwdf'></fieldset></dl></div>
                    1. <tfoot id='Irwdf'></tfoot>
                        <bdo id='Irwdf'></bdo><ul id='Irwdf'></ul>