我在我的网站中使用了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. 从字符串获取日期格式
- 4. 格式的NSDate从字符串日期
- 5. 从字符串格式化日期
- 6. 在VC++中使用区域设置格式化日期字符串
- 7. VB.Net日期字符串格式模式
- 8. 未来日期采摘
- 9. 转换日期从字符串格式到日期格式在mongodb
- 10. 从字符串格式到日期格式的隐藏日期输入
- 11. 从字符串到日期格式的日期更改格式3
- 12. 从cookie字符串格式转换为mysql日期格式的日期
- 13. 根据Firefox中的区域设置格式化“YYYY-MM-DD”日期字符串
- 14. 基于用户区域的iOS设置日期格式
- 15. 如何更改Windows用户的区域设置/日期格式?
- 16. Objective-C格式日期和字符串
- 17. 格式的字符串等的日期
- 18. 转换日期格式字符串
- 19. 字符串格式到日期
- 20. C#格式化字符串日期
- 21. 格式日期字符串在时刻
- 22. VBA:interpeting英语日期格式字符串
- 23. 格式日期时间字符串只
- 24. 字符串日期时间格式installdate
- 25. 字符串到日期格式
- 26. PHP日期字符串格式
- 27. C#格式字符串作为日期
- 28. 字符串日期时间格式
- 29. NSDateFormatter日期格式字符串
- 30. 格式化字符串日期与String.Format()
为什么不把访问者的语言环境设置为data-dojo-config?让Dojo为您选择合适的格式。 – peller 2013-03-09 03:22:10