473,320 Members | 1,940 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Short Date Format

Jo
Is there anyway we can know using JavaScript the Short Date Format
used in the
Control Panel -> Regional and Language Settings?

I know the using the combinations of following we can get the Locale
Long Name format

toString()
toLocaleString()
toLocaleDateString()
toLocaleTimeString()

But there is no direct function in JavaScript like
toLocaleShortDateString().

Are there any scripts available to find out what the user setting is.
I would not like to use Applet, VBScript or ActiveX Control

Thanks
Jul 23 '05 #1
4 19769
Jo wrote:
Is there anyway we can know using JavaScript the Short Date Format
used in the
Control Panel -> Regional and Language Settings?
Nope. The user agent has no access to that information. Some operating
systems don't even have a Control Panel -> Regional and Language
Settings.
Are there any scripts available to find out what the user setting is.
I would not like to use Applet, VBScript or ActiveX Control


You can't output the "short date" defined by any OS settings. You could
output *a* short date, but it may not be the one the user is expecting.

<script type="text/javascript">
function LZ(n) {
return (n > 9 ? n : '0' + n);
}
var d = new Date();
document.write(d.getFullYear() + '/' + LZ(d.getMonth() + 1) + '/' +
LZ(d.getDate()));
</script>

--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq

Jul 23 '05 #2
On Fri, 10 Sep 2004 21:00:28 GMT, Grant Wagner
<gw*****@agricoreunited.com> wrote:
Jo wrote:
Is there anyway we can know using JavaScript the Short Date Format used
in the Control Panel -> Regional and Language Settings?


Nope. The user agent has no access to that information. Some operating
systems don't even have a Control Panel -> Regional and Language
Settings.


Every OS I've ever used allows locale information to be specified. Any
program can access this data, but there is no requirement that a user
agent relays it to a script.

That said, ECMA-262 3rd Ed. does specify a toLocaleDateString method, but
I don't know how many current UAs will implement it[1]. If it's not
available, it would be best to format the date in an unambiguous manner,
either naming months, or using the yyyy-mm-dd format.

Taking the latter (preferable as it requires no localisation):

function formatDate(o) {
if(o.toLocaleDateString) {
return o.toLocaleDateString();
} else {
var d = o.getDate(), m = o.getMonth() + 1, y;
if(o.getFullYear) {y = o.getFullYear();}
else {y = 2000 + (o.getYear() % 100);}
return y + (10 > m ? '-0' : '-') + m
+ (10 > d ? '-0' : '-') + d;
}
}

[snip]

Mike
[1] The latest versions of Opera, Mozilla, Firefox, Netscape, and IE do.
Opera uses my short date format, whilst the others use the long date.

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #3
JRS: In article <opsd4r4egxx13kvk@atlantis>, dated Fri, 10 Sep 2004
21:42:35, seen in news:comp.lang.javascript, Michael Winter <M.Winter@bl
ueyonder.co.invalid> posted :

That said, ECMA-262 3rd Ed. does specify a toLocaleDateString method, but
I don't know how many current UAs will implement it[1].


Too few, I guess; but toLocaleString can be used with a RegExp to remove
any plausible time field.

But there is then the question of whether the localisation is correctly
implemented in the browser, and whether the computer is localised
correctly for the user, and whether the user thinks that it is.

Consider the case of an American reading a page displayed by a Korean in
our (English) Public Library, where the OS is incorrectly set for the UK
and Asian browsers are available. If he sees 02/03/04, he'll have
little idea what it may mean. If he sees 2004/03/02 or 2004-03-02, he
may be surprised but he should not be deceived.

As you imply, one should never localise or multi-nationalise if
internationalisation is possible.

Your year code assumes 2000-2099, of course, my getFY gets the full year
for any system and year (AFAICS).
GW's LZ, unlike mine, can return either a string or a number. In the
present context, that does not matter; but I'm not convinced that, for
all possible uses of such a function, it can never matter.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #4
wsabey
1
Every OS I've ever used allows locale information to be specified. Any
program can access this data, but there is no requirement that a user
agent relays it to a script.

That said, ECMA-262 3rd Ed. does specify a toLocaleDateString method, but
I don't know how many current UAs will implement it[1]. If it's not
available, it would be best to format the date in an unambiguous manner,
either naming months, or using the yyyy-mm-dd format.
I tried toLocaleDateString(); and IE 6.0 is returning the long date.
Are there any plans to add a short date method to javascript so we can designate which regional setting we want to access?
Mar 17 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Laurence Neville | last post by:
This is regarding a change in the Short Date format under Hebrew Regional Settings, that has caused huge problems in our ASP web application. The change appears to have been introduced sometime...
0
by: Galina | last post by:
Hello My form is based on a query returning rows of a table. Practically, it is based on a table, so simple the query is. A field on the form is formatted as short time. The column in the table,...
1
by: kgatchell2001 | last post by:
Hi, I am a beginner working on a database to manage clients, payroll, station assignments, etc. I have created a query which calculates age based on subtracting the date of birth from the current...
7
by: Edward Mitchell | last post by:
I have a number of DateTimePicker controls, some set to dates, some set to a format of Time. The controls are all embedded in dialogs. I created the controls by dragging the DateTime picker from...
3
by: MattB | last post by:
I've hit a snag with an application I wrote because of the differing date formats in different countries. It's a set of pages that make calls to a COM object that I have wrapped in a web...
6
by: ABC | last post by:
Is there any function return the short date format on the regional and Language Options under control panel?
2
by: savigliano | last post by:
hello, i am doing a date comparation and i have reallize that the data i have in my database (general date format) it is causing me problems, and because i don´t need the time data i would like to...
3
by: Matt Brown - identify | last post by:
Hello, I'm trying to figure out a method to look up by a range of dates, entries in a database. The format of the date in the database is "M\D \yyyy HH:MM:SS". What i need to do is take the...
5
OuTCasT
by: OuTCasT | last post by:
Hi. I would like to know how to convert the short date format to the long date format for my application without changing the regional settings from short date to long date. ?
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.