473,382 Members | 1,271 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,382 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 19775
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: 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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.