我在我的網站中使用了Dojo DateTextBox,它採用約束形式,如"dd-mm-yyyy"
等日期格式。我需要選擇訪問者的區域設置的日期格式字符串並將其傳遞給此DateTextBox以以本地格式顯示日期。我不需要獲取格式化日期的方法,但需要獲取格式字符串。從用戶區域採摘日期格式字符串
2
A
回答
0
嘗試此(參考:Where can I find documentation on formatting a date in JavaScript?):
<script type="text/javascript">
var d = new Date();
var curr_date = d.getDate();
var curr_month = d.getMonth() + 1;
var curr_year = d.getFullYear();
curr_date = (curr_date < 10 ? "0" + curr_date : curr_date);
curr_month = (curr_month < 10 ? "0" + curr_month : curr_month);
var formatted_date = "" + curr_date + "-" + curr_month + "-" + curr_year;
</script>
1
require(["dojo/i18n", "dojo/date/locale"], function(i18n) {
var defaultLocale = i18n.normalizeLocale();
var bundle = i18n.getLocalization("dojo.cldr", "gregorian", defaultLocale);
// all available formats
console.dir(bundle);
// some of them
console.log(bundle['dateFormat-full']);
console.log(bundle['dateFormat-long']);
console.log(bundle['dateFormat-medium']);
console.log(bundle['dateFormat-short']);
});
參見實例:http://jsfiddle.net/phusick/4ZDCv/
備選地直接要求經由dojo/i18n
插件本地化束:
require(["dojo/i18n!dojo/cldr/nls/gregorian"], function(gregorian) {
console.dir(gregorian); // all available formats
console.log(gregorian['dateFormat-full']);
});
的jsfiddle:http://jsfiddle.net/phusick/jJVEU/
編輯:dijit/form/DateTextBox
處理區域本身,因此很可能所有你需要的是設置formatLength
:
<input
data-dojo-type="dijit/form/DateTextBox"
data-dojo-props="constraints: { formatLength: 'long' }"
/>
一個例子它的工作原理與頁面上的多個地區:http://jsfiddle.net/phusick/PhHwg/
相關問題
- 1. 根據設備區域設置格式化日期字符串
- 2. 關於區域設置的日期格式字符串
- 3. Javascript格式日期從字符串到日期格式
- 4. 字符串日期格式
- 5. 格式字符串日期
- 6. 日期字符串格式
- 7. Javsascript日期,採摘者和時區
- 8. 從日期(字符串格式)選擇
- 9. 從字符串更改日期格式
- 10. 從字符串獲取日期格式
- 11. 從字符串格式化日期
- 12. 格式的NSDate從字符串日期
- 13. 從字符串格式化日期
- 14. 格式日期從字符串在javascript
- 15. 在VC++中使用區域設置格式化日期字符串
- 16. 如何與格式「DD/MM/YYYY」轉換日期字符串到OS當前區域性的日期格式
- 17. VB.Net日期字符串格式模式
- 18. C#將日期從字符串轉換爲日期格式
- 19. 如何從日期字符串中獲取日期格式?
- 20. 如何從日期字符串格式獲取日期對象
- 21. 格式化JSON日期格式化的日期基於區域
- 22. 未來日期採摘
- 23. 格式yyyy-MM-dd HH:mm:ss從字符串到日期格式
- 24. 從字符串到日期格式的日期更改格式3
- 25. 從字符串格式到日期格式的隱藏日期輸入
- 26. 從cookie字符串格式轉換爲mysql日期格式的日期
- 27. 轉換日期從字符串格式到日期格式在mongodb
- 28. 根據Firefox中的區域設置格式化「YYYY-MM-DD」日期字符串
- 29. 基於Android的用戶區域設置的日期格式
- 30. 基於用戶區域的iOS設置日期格式
爲什麼不把訪問者的語言環境設置爲data-dojo-config?讓Dojo爲您選擇合適的格式。 – peller 2013-03-09 03:22:10