Moment.js: does en locale allow to display time in 12 hours format?

I am using Moment.js 2.10.3. According to moment-with-locales.js:

var defaultLongDateFormat = {
    LTS  : 'h:mm:ss A',
    LT   : 'h:mm A',
    L    : 'MM/DD/YYYY',
    LL   : 'MMMM D, YYYY',
    LLL  : 'MMMM D, YYYY LT',
    LLLL : 'dddd, MMMM D, YYYY LT'
};

      

Does this mean that the en locale should display the time in 12 hours format with LTS format?

jsfiddle demonstrating the problem

Sorry my English is not very good right now ...

var locale = "en";
var timeOffset = 540;

var currentTimeOffset = moment().utcOffset(timeOffset).locale(locale).format("LTS");
document.getElementById("timeOffset").innerHTML = currentTimeOffset;

var elLocale = moment.utc(currentTimeOffset, "LTS", 'el');

document.getElementById("elLocaleHours").innerHTML = elLocale.hours();
document.getElementById("elLocaleMinutes").innerHTML = elLocale.minutes();
document.getElementById("elLocaleSeconds").innerHTML = elLocale.seconds(); 


var enLocale = moment.utc(currentTimeOffset, "LTS", locale); 

document.getElementById("enLocaleHours").innerHTML = enLocale.hours();
document.getElementById("enLocaleMinutes").innerHTML = enLocale.minutes();
document.getElementById("enLocaleSeconds").innerHTML = enLocale.seconds(); 

var beLocale = moment.utc(currentTimeOffset, "LTS", 'be'); 

document.getElementById("beLocaleHours").innerHTML = beLocale.hours();
document.getElementById("beLocaleMinutes").innerHTML = beLocale.minutes();
document.getElementById("beLocaleSeconds").innerHTML = beLocale.seconds(); 
      

<script src="http://momentjs.com/downloads/moment-with-locales.min.js"></script>
<div id="timeOffset"></div>
<div id="elLocale"> elLocale (should be 12 h format) :
    <span id="elLocaleHours"></span>&nbsp; : &nbsp;
    <span id="elLocaleMinutes"></span>&nbsp; : &nbsp;
    <span id="elLocaleSeconds"></span>
</div>
<div id="enLocale"> enLocale (should be 12 h format) :
    <span id="enLocaleHours"></span>&nbsp; : &nbsp;
    <span id="enLocaleMinutes"></span>&nbsp; : &nbsp;
    <span id="enLocaleSeconds"></span>
</div>

<div id="beLocale"> beLocale (should be 24 h format) :
    <span id="beLocaleHours"></span>&nbsp; : &nbsp;
    <span id="beLocaleMinutes"></span>&nbsp; : &nbsp;
    <span id="beLocaleSeconds"></span>
</div>
      

Run codeHide result


+3


source to share


1 answer


According to the docs, I would expect to enLocale.hours()

always return hours in a range 0 - 23

:

http://momentjs.com/docs/#/durations/hours/

Like other duration getters, moment.duration (). hours () gets the hours (0 - 23).

http://momentjs.com/docs/#/get-set/hour/



Accepts numbers from 0 to 23. If the range is exceeded, it will bubble until a day.

Instead, you can display it using format()

, which is based on a specific language version:

Because the preferred formatting differs from the language, there are several that can be used to format a moment based on its locale.

+1


source







All Articles