久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Moment.js 的語言環境和特定日期格式

Locale and specific date format with Moment.js(Moment.js 的語言環境和特定日期格式)
本文介紹了Moment.js 的語言環境和特定日期格式的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我在我的項目中使用 Moment.js 并將日期格式化如下:

I am using Moment.js in my project and formatting dates as follows:

var locale = window.navigator.userLanguage || window.navigator.language;
moment.locale(locale);
someDate.format("L");

效果很好,但有時我需要顯示一個沒有年份的日期.我不能使用像 someDate.format("MM/DD") 這樣的東西,因為在某些語言中它應該是 someDate.format("DD/MM").我需要類似 L,LL,LLL 但沒有年份的東西.

It works well but sometimes I need show a date without a year. I can't use something like someDate.format("MM/DD") because in some languages it should be someDate.format("DD/MM"). I need something like L,LL,LLL but without the year.

我能做什么?

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'

推薦答案

好的.這有點糟糕,但你知道它會是這樣.

Okay. This is a little awful, but you knew it was going to be.

首先,您可以訪問(例如)'L'的實際格式字符串:

First, you can access the actual format string for (for instance) 'L':

var formatL = moment.localeData().longDateFormat('L');

接下來,您可以通過明智的正則表達式替換對其進行一些手術:

Next, you can perform some surgery on it with judicious regex replacement:

var formatYearlessL = formatL.replace(/Y/g,'').replace(/^W|W$|WW/,'');

(也就是說:刪除YYYY,加上刪除后留下的孤立分隔符)

(Which is to say: Remove YYYY, plus the orphaned separator left by its removal)

然后您可以在瞬間格式調用中使用您的新格式字符串:

Then you can use your new format string in a moment format call:

someDate.format(formatYearlessL);

這必然做出一些假設:

  • 區域設置的月 + 日數字格式的順序與該區域設置的年 + 月 + 日格式的順序匹配,但刪除了年份.
  • 短格式僅在月和日之間使用分隔符(沒有前導/尾隨分隔符).
  • 短數字日期格式的分隔符始終為非字母數字.
  • 格式由數字元素和分隔符組成,而不是帶有文章的句子格式(請參閱下面 RGPT 關于西班牙語和葡萄牙語的評論,這也適用于其他一些語言的長格式).

快速回顧一下 locale/*.js,這些假設適用于我檢查的每個語言環境文件,但可能存在一些違反它們的語言環境.(ETA:下面的評論指出德國短日期格式違反了第二個假設)

On a quick review of locale/*.js, these assumptions hold true for every locale file I examined, but there may be some locales that violate them. (ETA: a comment below points out that a German short date format violates the second assumption)

另外一個重要的警告是,這很可能是脆弱的.完全有可能moment.js的未來版本會改變當前在longDateFormat中的數據位置...

As an additional important caveat, this is likely to be fragile. It is entirely possible that a future version of moment.js will change the location of the data currently in longDateFormat...

這篇關于Moment.js 的語言環境和特定日期格式的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How to fix BrowserWindow is not a constructor error when creating child window in Electron renderer process(在 Electron 渲染器進程中創建子窗口時如何修復 BrowserWindow 不是構造函數錯誤) - IT屋-程序員軟件開發技術
mainWindow.loadURL(quot;https://localhost:3000/quot;) show white screen on Electron app(mainWindow.loadURL(https://localhost:3000/) 在 Electron 應用程序上顯示白屏)
Electron webContents executeJavaScript : Cannot execute script on second on loadURL(Electron webContents executeJavaScript:無法在第二個 loadURL 上執行腳本)
how to use electron browser window inside components in angular-cli?(如何在angular-cli的組件內使用電子瀏覽器窗口?)
ElectronJS - sharing redux store between windows?(ElectronJS - 在 Windows 之間共享 redux 存儲?)
How to access camera/webcamera inside electron app?(如何在電子應用程序中訪問相機/網絡攝像頭?)
主站蜘蛛池模板: 我想看一级黄色毛片 | 国产在线精品一区二区三区 | 久久这里只有精品首页 | 二区在线视频 | 天堂视频中文在线 | 99久久精品免费看国产四区 | 玩丰满女领导对白露脸hd | 女同久久 | 欧美日韩精品一区二区三区视频 | 一区二区三区免费观看 | 天天玩天天操天天干 | 黄色一级大片在线免费看产 | 日本粉嫩一区二区三区视频 | 欧洲尺码日本国产精品 | 国产精品久久久久久久免费大片 | 欧美人妇做爰xxxⅹ性高电影 | 国产精品免费观看视频 | 一区二区视频免费观看 | 日韩在线欧美 | www97影院| 亚洲香蕉 | 亚洲伊人久久综合 | 一级高清视频 | 中国美女一级黄色片 | 国产一区二区在线播放 | 欧美精品欧美精品系列 | 亚洲精品久久久久久国产精华液 | 国产精品久久一区二区三区 | 一区二区视频在线 | 日韩成人在线一区 | 亚洲一区二区三 | 玖玖玖在线 | 午夜影院在线观看免费 | 综合色站导航 | 亚洲国产一区二区在线 | 亚洲 欧美 综合 | 成人在线免费视频 | 日韩乱码一二三 | 国产成人免费视频网站高清观看视频 | 韩国av电影网 | 中文字幕在线一区二区三区 |