NSDate实例以NSLocale本地化格式输出
来源:互联网 发布:mac装机必备软件 编辑:程序博客网 时间:2024/05/20 23:03
Overview
Instances of NSDateFormatter create string representations of NSDate (and NSCalendarDate) objects, and convert textual representations of dates and times into NSDate objects. You can express the representation of dates and times flexibly using pre-set format styles or custom format strings.
In general, you are encouraged to use format styles (see timeStyle, dateStyle, and NSDateFormatterStyle) rather than using custom format strings, since the format for a given style reflects a user’s preferences. Format styles also reflect the locale setting.
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setTimeStyle:NSDateFormatterNoStyle];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];
NSDate *date = [NSDate dateWithTimeIntervalSinceReferenceDate:118800];
NSLocale *usLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
[dateFormatter setLocale:usLocale];
NSLog(@"Date for locale %@: %@",
[[dateFormatter locale] localeIdentifier], [dateFormatter stringFromDate:date]);
// Output:
// Date for locale en_US: Jan 2, 2001
NSLocale *frLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"fr_FR"];
[dateFormatter setLocale:frLocale];
NSLog(@"Date for locale %@: %@",
[[dateFormatter locale] localeIdentifier], [dateFormatter stringFromDate:date]);
// Output:
// Date for locale fr_FR: 2 janv. 2001
http://www.cocoachina.com/bbs/simple/?t17840.html
- NSDate实例以NSLocale本地化格式输出
- NSDate,NSDateFormatter,NSLocale
- iOS_本地化设置NSLocale
- iOS NSLocale(本地化语言)
- NSDate,日期格式的灵活输出
- NSDate、NSTimeInterval、NSDateFormatter、NSLocale 、NSTimeZone、NSDateComponents详解
- OC中NSDate对象的输出时差解决即时区本地化问题
- 17 Foundation框架之NSDate、NSDateFormatter、NSDateComponents、NSCalendar、NSLocale、NSTimer
- NSLocale
- NSLocale
- NSLocale
- iOS 封装本地化相关信息 NSLocale类介绍
- 将一个数字以字符格式输出
- 将整数以二进制格式输出
- 将SAP订单以XML格式输出
- 以Html格式输出自动化测试报告
- .net 以table输出格式导出excel
- 将数字以“M”的格式输出
- 现实世界的Windows Azure:采访Applied Information Science的技术总监Vishwas Lele
- 关于web service 的问题
- android图像处理系列之六--给图片添加边框(下)-图片叠加
- 关于FPGA加密问题
- XSS,跨站脚本攻击(Cross Site Scripting)
- NSDate实例以NSLocale本地化格式输出
- ubuntu配置adb环境变量
- 说说Erlang的Special Process和SASL Error Logging
- 人员管理之感想
- android图像处理系列之五--给图片添加边框(中)
- WP 虚拟ListBox
- linux和windows下分别如何查看电脑是32位的还是64位?
- MFC之工厂模式(C++ & java)
- 什么时候加上android.intent.category.DEFAULT和LAUNCHER