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

顯示日期和月份,根據區域設置不顯示年份

display day and month, without a year according to locale(顯示日期和月份,根據區域設置不顯示年份)
本文介紹了顯示日期和月份,根據區域設置不顯示年份的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

有沒有更好的方法從包含位置適當分隔符的日期中僅獲取日和月?

Is there any better way for getting only day and month from a date including location appropriate separator?

我有一個先獲取分隔符的解決方案:

I have a solution that gets separator first:

 function getDateSep() {
   var temp = moment().format('L');
   var locale = moment().locale;
   var datesep = temp.substring(5, 6);
   return datesep;
}

然后像這樣構建日期:

var sep = function getDateSep()
var date = date.format('D' + sep + 'M'+ sep)

是否有動態構建整個日期的解決方案?

Is there a solution that builds the whole date dynamically?

我想要達到的結果是:31.01 (dd.mm)31/01 (日/毫米)01.31 (mm.dd)01/31 (mm/dd) 等

The result I want to achieve would be like: 31.01 (dd.mm) 31/01 (dd/mm) 01.31 (mm.dd) 01/31 (mm/dd) etc

推薦答案

如鏈接問題中所述:實現所需的一種方法是獲取本地化 longDateFormat,然后使用正則表達式刪除年份部分.

Daniel T. 在評論中強調該解決方案不適用于 en-CA 等語言環境,因此我將提供考慮到 一些 的更新解決方案> 以年份部分開頭的其他語言環境.

Daniel T. highlighted in comments that the solution will not work in locales like en-CA, so I'm going to provide an updated solution that takes in account some other locales that starts with year part.

如果您需要支持 every 語言環境,您可以使用 ad hoc 條件來定位它們,就像我在以下代碼段中為 ar-ly 所做的那樣.

Probably there are some other locales the are not convered with /.YYYY/ and /YYYY./ RegExp, if you need to support every locale you can target them with ad hoc condition, as I made for ar-ly in the following snippet.

這里的代碼示例顯示了不同語言環境中可能的輸出:

Here a code sample the shows possible output in various locales:

function changeLang(value){
  moment.locale(value);
  
  // Get locale data
  var localeData = moment.localeData();
  var format = localeData.longDateFormat('L');
  
  // Manage custom cases
  if( value === "ar-ly"){
    format = 'D/u200FM';
  }
  // if( value === ...) possible othter cases
  
  // Check locale format and strip year
  if( format.match(/.YYYY/g) ){
    format = format.replace(/.YYYY/, '');
  }
  if( format.match(/YYYY./g) ){
    format = format.replace(/YYYY./, '');
  }

  var res = moment().format(format);
  
  $("#result").html(res);
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.17.1/moment-with-locales.min.js"></script>

<select onchange="changeLang(value)">
  <option value="en">EN</option>
  <option value="en-CA">en-CA (Canada)</option>
  <option value="eo">eo (Esperanto)</option>
  <option value="de">DE</option>
  <option value="it">IT</option>
  <option value="hu">hu (Hungarian)</option>
  <option value="ja">ja (Japanese)</option>
  <option value="lv">lv (Latvian)</option>
  <option value="fr">FR</option>
  <option value="zh-hk">zh-hk - Chinese (Hong Kong)</option>
  <option value="ar-ly">ar-ly - Arabic (Lybia)</option>
</select>

<div id="result"></div>

這篇關于顯示日期和月份,根據區域設置不顯示年份的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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?(如何在電子應用程序中訪問相機/網絡攝像頭?)
主站蜘蛛池模板: 视频一区二区在线 | 色综合天天综合网国产成人网 | 欧美精品一区二区三区四区 在线 | 视频一区二区中文字幕 | 91影院 | 久久一区二区三区电影 | 91国产精品 | 99爱在线观看 | 精品欧美一区二区三区久久久 | 色播久久久 | 三级黄视频在线观看 | 亚洲精品一区在线观看 | 99精品欧美 | 亚洲九色 | 国产综合久久 | 99re在线视频观看 | 欧美成人精品在线 | 黄色免费网站在线看 | 亚洲欧洲精品在线 | 99在线免费观看 | 欧美久| 免费v片在线观看 | 插插插干干干 | 国产小视频自拍 | 亚洲视频一区二区三区 | 免费xxxx大片国产在线 | 欧美日韩国产一区 | 国产一区二区三区在线观看免费 | 国产日韩欧美一区 | 成人午夜在线 | 亚洲一二三区不卡 | 在线国产精品一区 | 日韩av在线播 | 久久久不卡网国产精品一区 | 毛片av免费在线观看 | 精品国偷自产在线 | 婷婷在线免费 | 精品亚洲91 | 丝袜美腿一区二区三区 | 一区二区三区精品视频 | 午夜午夜精品一区二区三区文 |