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

  • <small id='N6Crh'></small><noframes id='N6Crh'>

    • <bdo id='N6Crh'></bdo><ul id='N6Crh'></ul>
  • <tfoot id='N6Crh'></tfoot>
  • <legend id='N6Crh'><style id='N6Crh'><dir id='N6Crh'><q id='N6Crh'></q></dir></style></legend>

        从字符串创建 NSDate

        时间:2023-08-31

          <bdo id='tNv5N'></bdo><ul id='tNv5N'></ul>
            <legend id='tNv5N'><style id='tNv5N'><dir id='tNv5N'><q id='tNv5N'></q></dir></style></legend>
          1. <small id='tNv5N'></small><noframes id='tNv5N'>

              <tbody id='tNv5N'></tbody>

              • <tfoot id='tNv5N'></tfoot>
                1. <i id='tNv5N'><tr id='tNv5N'><dt id='tNv5N'><q id='tNv5N'><span id='tNv5N'><b id='tNv5N'><form id='tNv5N'><ins id='tNv5N'></ins><ul id='tNv5N'></ul><sub id='tNv5N'></sub></form><legend id='tNv5N'></legend><bdo id='tNv5N'><pre id='tNv5N'><center id='tNv5N'></center></pre></bdo></b><th id='tNv5N'></th></span></q></dt></tr></i><div id='tNv5N'><tfoot id='tNv5N'></tfoot><dl id='tNv5N'><fieldset id='tNv5N'></fieldset></dl></div>
                  本文介绍了从字符串创建 NSDate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我有一个像这样的 NSString:@"3/15/2012 9:15 PM" 我想把它转换成 NSDate,我是这样做的:

                  I have an NSString like this: @"3/15/2012 9:15 PM" and I would like to convert it to NSDate, I have done like this:

                  NSString *str =@"3/15/2012 9:15 PM";
                  NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
                  [formatter setDateFormat:@"mm/dd/yyyy HH:mm"];
                  NSDate *date = [formatter dateFromString:];
                  
                  NSLog(@"%@", date);  // date = null
                  

                  你能帮帮我吗,谢谢.

                  推荐答案

                  使用如下解决方案

                  NSString *str = @"3/15/2012 9:15 PM";
                  NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
                  
                  formatter.dateFormat = @"MM/dd/yyyy HH:mm a";
                  
                  NSDate *date = [formatter dateFromString:str];
                  
                  NSLog(@"%@", date);
                  

                  对不起,格式应该如下:

                  Sorry, the format should be as follows:

                  formatter.dateFormat = @"MM/dd/yyyy hh:mm a";
                  

                  显示的时间将是格林威治标准时间.因此,如果您添加/减去时区,将是晚上 9:15.

                  And the time shown will be GMT time. So if you add/subtract the timezone, it would be 9:15 PM.

                  #2

                  如下使用.你也会得到准确的时间.

                  Use as below. You would get exact time too.

                  NSString *str = @"3/15/2012 9:15 PM";
                  
                  NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
                  
                  formatter.dateFormat = @"MM/dd/yyyy hh:mm a";
                  
                  NSTimeZone *gmt = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
                  
                  formatter.timeZone = gmt;
                  
                  NSDate *date = [formatter dateFromString:str];
                  
                  NSLog(@"%@",date);
                  

                  这篇关于从字符串创建 NSDate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  • <bdo id='pYy9m'></bdo><ul id='pYy9m'></ul>

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

                          <tfoot id='pYy9m'></tfoot>

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