dateFromString 和莫斯科时间

发布于 2024-11-19 16:04:16 字数 594 浏览 1 评论 0原文

我正在使用这段代码将字符串转换为日期:

+(NSDate*)dateTexteFromString:(NSString*)someString
{
    NSDateFormatter *df = [[NSDateFormatter alloc] init];
    NSLocale *locale = [[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"] autorelease];
    [df setLocale:locale];
    [df setDateFormat:@"EEE, dd MMM yyyy hh:mm a zzz"];
    NSDate *myDate = [df dateFromString: someString];
    [df release];
    return myDate;
}

它对于大多数日期都可以正常工作,但是这个让我发疯:

2011 年 7 月 12 日星期二上午 12:28 MSD

(莫斯科)。我应该怎么办?还有其他像这个一样无法识别的时区吗?我无法尝试世界上所有时区:(

I'm using this code to convert a string to a date :

+(NSDate*)dateTexteFromString:(NSString*)someString
{
    NSDateFormatter *df = [[NSDateFormatter alloc] init];
    NSLocale *locale = [[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"] autorelease];
    [df setLocale:locale];
    [df setDateFormat:@"EEE, dd MMM yyyy hh:mm a zzz"];
    NSDate *myDate = [df dateFromString: someString];
    [df release];
    return myDate;
}

It works fine for most dates, but this one drives me crazy:

Tue, 12 Jul 2011 12:28 am MSD

(Moscow). What should I do? And is there other unrecognized timezone like this one? I can't try all timezones over the world :(

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

扭转时空 2024-11-26 16:04:16

使用 MSKS 而不是 MSD 或通过执行以下操作查找您需要的内容:

  1. 首先使用查找可用的时区名称

    NSLog(@"%@", [NSTimeZoneknownTimeZoneNames]);
    
  2. 然后复制您想要的名称(我复制了欧洲/莫斯科)并使用此代码查找缩写

    NSTimeZone *timeZone = [NSTimeZone timeZoneWithName:@"欧洲/莫斯科"];
    NSLog(@"%@",[时区缩写]);
    

Use MSKS instead of MSD or find what you need by doing this:

  1. First find the available time zone names using

    NSLog(@"%@", [NSTimeZone knownTimeZoneNames]);
    
  2. Then copy the name that you want (i copied Europe/Moscow) and use this code to find the abbreviation

    NSTimeZone *timeZone = [NSTimeZone timeZoneWithName:@"Europe/Moscow"];
    NSLog(@"%@",[timeZone abbreviation]);
    
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文