转换字符串日期格式 [英] Convert string date format

查看:107
本文介绍了转换字符串日期格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在此格式中有字符串日期星期二,2012年10月23日01:05:00 +0000。现在我想将日期格式转换为 TUE OCT 23 2012 1:05 AM 。最好的方法是什么?

I have date in string in this formate "Tue, 23 Oct 2012 01:05:00 +0000". Now i want to convert date format to "TUE OCT 23 2012 1:05AM". What is the best way to do this?

推荐答案

NSString *dateStr = @"Tue, 25 May 2010 12:53:58 +0000";

// Convert string to date object
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"EE, d LLLL yyyy HH:mm:ss Z"];
NSDate *date = [dateFormat dateFromString:dateStr]; 

但首先


  1. 创建 NSDateFormatter ,将日期字符串转换为 NSDate
    对象。

  2. 创建第二个 NSDateFormatter (或首先更改
    的格式字符串)以转换 NSDate 返回字符串。

  1. Create a NSDateFormatter to convert the date string to a NSDate object.
  2. Create a second NSDateFormatter (or change the format string of the first) to convert the NSDate back to a string.

这会有点帮助???

编辑

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"UTC"]];
[dateFormatter setDateFormat:@"yyyy-MM-ddHH:mm:ss"];
NSDate *date = [dateFormatter dateFromString:@"2011-04-0600:28:27"];

这篇关于转换字符串日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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