in Education by
I just realized that the l (or localize) method in Rails (3.1.3 at the moment) appears to not manage the clock format base on the currently set locale. I have just assumed this was the case and not tested for this specifically... I have just verified that dates were re-formatted according to the locale. I get a 24-hour clock for all of the following in my rails console. The only visible difference between the two locales is capitalization of the month name. I18n.l Time.now, :format => :short, :locale => :"en" I18n.l Time.now + 12.hours, :format => :short, :locale => :"en" I18n.l Time.now, :format => :short, :locale => :"sv-SE" I18n.l Time.now + 12.hours, :format => :short, :locale => :"sv-SE" Now, why is that? Is this not part of localizing a time? The only manual intervention of AM/PM I find is in generating the selects for forms where I can demand 12-hour clock "manually". An odd choice since it feels to me like just the kind of thing I want to rely on the locale for. Looking at Mac OS, I do get to choose the language and the locale for format preferences separately, but that is why we have the en-US, en-GB, sv-SE naming, right? Signifying language-COUNTRY. It would be perfectly OK for me to add a en-SE file to my app containing English translations by formatting suitable in Sweden. I assume not all US-developers go in and edit the defaults locale file for English (en-US looks the same as en btw) to get a 12-hour clock suitable for US users. So, feel free to show me how dumb I am. I fully expect this problem to be sure to something really really basic. In short. What I am getting wrong? And how do I "fix" my timestamps? :) JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
You can get a 12-hour clock if you specify it directly with %I.%m %p: %p means indicator (“AM” or “PM”), %I means hour of the day for a 12-hour clock (01..12) >> I18n.l Time.now, :format => "%I.%m %p", :locale => :"en" => "01.12 pm" >> I18n.l Time.now + 12.hours, :format => "%I.%m %p", :locale => :"en" => "01.12 am" This works in Rails 3.1

Related questions

0 votes
    Which of these formatting strings of SimpleDateFormat class is used to print AM or PM in time? (a) a (b ... Regular Expressions of Java Select the correct answer from above options...
asked Feb 24, 2022 in Education by JackTerrance
0 votes
    There is a clock which shows false timing ie it shows 20 minutes less for each 1 hour. If the clock shows 12 noon now how ... ) 36 minutes B) 48 minutes C) 35 minutes D) 60 minutes...
asked Feb 14, 2021 in Education by JackTerrance
0 votes
    I have several properties that are dependent on the environment the application is running. For example, there ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 20, 2022 in Education by JackTerrance
0 votes
    Which of these methods is not a Locale class? (a) UK (b) US (c) INDIA (d) KOREA I had been asked ... - More Utility Classes of Java Select the correct answer from above options...
asked Feb 23, 2022 in Education by JackTerrance
0 votes
    Which of these methods is not a Locale class? (a) UK (b) US (c) INDIA (d) KOREA I had ... questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Oct 24, 2021 in Education by JackTerrance
0 votes
    After editing my UIScrollView size, page control stopped working. You can see there are only 3 slides. But ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 19, 2022 in Education by JackTerrance
0 votes
    This question already has answers here: JavaScript: Difference between .forEach() and .map() (15 answers) ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    Why is Google AdWords Keyword Planner not displaying actual no of searches?...
asked Mar 5, 2021 in Technology by Editorial Staff
0 votes
    Which of these method of Locale class can be used to obtain country of operation? (a) getCountry() (b) ... Utility Classes of Java Select the correct answer from above options...
asked Feb 23, 2022 in Education by JackTerrance
0 votes
    Kirchhoff's Current law is based on the law of conservation of ___________ (a) energy (b) momentum (c) mass (d ... for GATE EC Exam, Network Theory MCQ (Multiple Choice Questions)...
asked Oct 20, 2021 in Education by JackTerrance
0 votes
    What will be the syntax to find current date and time in format "YYYY-MM-DD"?...
asked Dec 18, 2020 in Technology by JackTerrance
0 votes
    A web-based software that is used to create interactive stories in Choose Your Own Adventure Format (CYOA) is ... d) Inklewriter Select the correct answer from above options...
asked Nov 13, 2021 in Education by JackTerrance
...