开发者

Format date based on the culture using datejs plugin

i'm using datejs library and i have a problem with the date format. I need to print to the screen todays date without the hour. When i run this line:

Date.today().toString('d')

i'm getting the date portion of the date(i.e 15).

If you look at the documentation they specify that 'd' as standard date should be depanded on the culture - and this is exactly what i want. http://code.google.com/p/datejs/wiki/FormatSpecifiers

i expect it to print mm/dd/yyyy if i'm using

<script type="text/javascript" src="/scripts/date.js"></script>

while if i'm using en-GB

<script type="text/javascript" src="/scripts/date-en-GB.js"></script>

to print dd/mm/yyyy

i know that i can specify formatstring in the tostring() or something like this:

(Date.today().toString(Date.CultureInfo.formatPatterns.shortDa开发者_JS百科te)

But I much rather prefer to use the d option.

Thanks for any help, Pini.


A couple issues here:

1) The wiki docs differ from the docs on the main page of http://code.google.com/p/datejs/ in that the main page describes the specifier you want as a custom specifier, not a standard one. The docs on the wiki appear to suggest that using multiple characters should trigger the custom mode, but this does not occur as you also indicate. I didn't see any bugs reporting this, so maybe you'd like to do so yourself and get notified of responses: http://code.google.com/p/datejs/issues/list

2) You should be able to do Date.today().toShortDateString(); but there appears to be a bug here (in all culture files). The source lists:

Date.prototype.toShortDateString=function(){
    return this.toString(Date.CultureInfo.formatPatterns.shortDatePattern);
};

... but the format pattern should be Date.CultureInfo.formatPatterns.shortDate (or the patterns should be defined differently or with synonyms). See http://code.google.com/p/datejs/issues/detail?id=116 .

3) The only place I found one could get support for the "custom" specifiers with their abbreviated letters was by also including the test/scripts/date-functions.js file.

<script type="text/javascript" src="build/date-en-US.js"></script>
<script type="text/javascript" src="test/scripts/date-functions.js"></script>
<script>
alert(Date.today().dateFormat('d'));
</script>

You might bring this up if you report the issue, as it seems unreliable to include a file located only in a "test" folder to get the functionality you want.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜