2009-07-09 21 views

回答

0

你可能想看看NSLocale ...檢查Locales Programming Guide。讓您的日期格式化與常量從NSDateFormatter.h

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; 
[dateFormatter setDateStyle:NSDateFormatterMediumStyle]; 

應該做正確的事就由他們的系統設置,用戶設置的語言環境。

您可以用[dateFormatter locale]檢查格式化程序的當前區域設置。

2

我不得不本地化小時,關於用戶PREF(軍用時間,24H)顯示小時 這裏是我的代碼:

NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; 
[dateFormatter setLocale: [NSLocale currentLocale]]; 
[dateFormatter setDateStyle:kCFDateFormatterNoStyle]; 
[dateFormatter setTimeStyle:kCFDateFormatterShortStyle]; 

NSLog([dateFormatter stringFromDate:[NSDate dateWithTimeIntervalSince1970:currentSong.timestamp]]); 
2

要本地化您的應用程序名稱:

  1. 做一個語言環境英文文件夾爲en.lproj,德文文件爲de.lproj,法文版爲fr.lproj,您的Xcode項目文件夾內爲

  2. 在每個*.lproj文件夾中,通過Xcode創建一個名爲InfoPlist.strings的文件:

    a。點擊File菜單並選擇New File...

    b。選擇Other組並點擊Strings

    c。添加新的字符串與所需的名稱在所需的語言文件夾

  3. 在您的Xcode項目文件,瀏覽到InfoPlist.strings項目並打開其三角形

  4. 點擊en英語,並添加字符串:

    CFBundleDisplayName = "AppNameInEnglish";

    對於德語,點擊de並添加字符串:

    CFBundleDisplayName = "AppNameAufDeutsch";

    ,...等

0

選擇「APPNAME」 -Info.plist,命令我,並在窗口中選擇「使文件本地化」。返回到「常規」選項卡,然後使用「添加本地化」按鈕添加本地化設置。

1

你不需要做任何特殊的事情來本地化日期時間。 NSDateFormatter默認執行此操作。你沒有看到理想行爲的原因(我假定你問這個問題的原因)是你可能沒有正確設置你的區域格式。僅僅設置語言是不夠的。在您的測試設備上更改「地區格式」,您將看到您的日期本地化:設置 - >國際 - >地區格式

2

如果您想本地化日期首先使用以下方法將日期轉換爲雙精度 double double_date = )[date timeIntervalSince1970]; 之後,您可以使用以下代碼將任何格式的雙值轉換爲

NSDateFormatter *dateformater =[[NSDateFormatter alloc] init]; 
    [dateformater setLocale:[NSLocale currentLocale]]; 
    [dateformater setDateStyle:NSDateFormatterLongStyle];//set current locale 
    [dateformater setTimeStyle:NSDateFormatterShortStyle]; 
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:dateinDouble];//it return the the date according to the locale formate 
相關問題