【问题标题】:MomentFromNow return wrong result in moment.jsMomentFromNow 在 moment.js 中返回错误的结果
【发布时间】:2019-01-06 20:06:30
【问题描述】:

我有这个过滤器

angular.module('app')
.filter('momentFromNow', function () {
    return function (input) {
        return moment(input).fromNow();
    };
});

并且 cookie 中的 Abp.Localization.CultureName 值为 "fa-IR" 。但是 momentFromNow 过滤器返回值例如是“2 分钟前”,它应该是“2 دقیقهپیش”。我该如何解决这个问题。 我的项目模板是aspnetboilerplate+SPA+ASP.Net MVC5x 工作3小时后: 如果站点托管在 Windows Server2012R2 中,它可以正常工作,但在 WindowsServer2016 中则不能。 有什么解决办法吗?

【问题讨论】:

  • 好像和dotnetversion>4.6.1有关

标签: angularjs localization momentjs aspnetboilerplate windows-server-2016


【解决方案1】:

您需要更改当前的语言环境 将脚本标签添加到您的 layout.cshtml

 <script type="text/javascript">
        abp.localization.currentCulture = $.extend({}, abp.localization.currentCulture, { displayNameEnglish: '@CultureInfo.CurrentUICulture.EnglishName' });
        moment.locale('@(CultureHelper.UsingLunarCalendar ? "en": CultureInfo.CurrentUICulture.Name )'); //Localizing moment.js
    </script>

您也可以像下面这样更改本地:

moment.locale('fr', {
    months : 'janvier_février_mars_avril_mai_juin_juillet_août_septembre_octobre_novembre_décembre'.split('_'),
    monthsShort : 'janv._févr._mars_avr._mai_juin_juil._août_sept._oct._nov._déc.'.split('_'),
    monthsParseExact : true,
    weekdays : 'dimanche_lundi_mardi_mercredi_jeudi_vendredi_samedi'.split('_'),
    weekdaysShort : 'dim._lun._mar._mer._jeu._ven._sam.'.split('_'),
    weekdaysMin : 'Di_Lu_Ma_Me_Je_Ve_Sa'.split('_'),
    weekdaysParseExact : true,
    longDateFormat : {
        LT : 'HH:mm',
        LTS : 'HH:mm:ss',
        L : 'DD/MM/YYYY',
        LL : 'D MMMM YYYY',
        LLL : 'D MMMM YYYY HH:mm',
        LLLL : 'dddd D MMMM YYYY HH:mm'
    },
    calendar : {
        sameDay : '[Aujourd’hui à] LT',
        nextDay : '[Demain à] LT',
        nextWeek : 'dddd [à] LT',
        lastDay : '[Hier à] LT',
        lastWeek : 'dddd [dernier à] LT',
        sameElse : 'L'
    },
    relativeTime : {
        future : 'dans %s',
        past : 'il y a %s',
        s : 'quelques secondes',
        m : 'une minute',
        mm : '%d minutes',
        h : 'une heure',
        hh : '%d heures',
        d : 'un jour',
        dd : '%d jours',
        M : 'un mois',
        MM : '%d mois',
        y : 'un an',
        yy : '%d ans'
    },
    dayOfMonthOrdinalParse : /\d{1,2}(er|e)/,
    ordinal : function (number) {
        return number + (number === 1 ? 'er' : 'e');
    },
    meridiemParse : /PD|MD/,
    isPM : function (input) {
        return input.charAt(0) === 'M';
    },
    // In case the meridiem units are not separated around 12, then implement
    // this function (look at locale/id.js for an example).
    // meridiemHour : function (hour, meridiem) {
    //     return /* 0-23 hour, given meridiem token and hour 1-12 */ ;
    // },
    meridiem : function (hours, minutes, isLower) {
        return hours < 12 ? 'PD' : 'MD';
    },
    week : {
        dow : 1, // Monday is the first day of the week.
        doy : 4  // Used to determine first week of the year.
    }
});

https://momentjs.com/docs/#/i18n/changing-locale/

【讨论】:

    猜你喜欢
    • 2013-11-08
    • 1970-01-01
    • 2021-12-21
    • 2015-05-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多