473,883 Members | 1,589 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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( )
toLocaleDateStr ing()
toLocaleTimeStr ing()

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

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 19820
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*****@agrico reunited.com>
comp.lang.javas cript FAQ - http://jibbering.com/faq

Jul 23 '05 #2
On Fri, 10 Sep 2004 21:00:28 GMT, Grant Wagner
<gw*****@agrico reunited.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 toLocaleDateStr ing 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.toLocaleDa teString) {
return o.toLocaleDateS tring();
} else {
var d = o.getDate(), m = o.getMonth() + 1, y;
if(o.getFullYea r) {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 <opsd4r4egxx13k vk@atlantis>, dated Fri, 10 Sep 2004
21:42:35, seen in news:comp.lang. javascript, Michael Winter <M.Winter@bl
ueyonder.co.inv alid> posted :

That said, ECMA-262 3rd Ed. does specify a toLocaleDateStr ing 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
internationalis ation 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.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #4
wsabey
1 New Member
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 toLocaleDateStr ing 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 toLocaleDateStr ing(); 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
4852
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 before Windows 2000 Service Pack 4 and has remained through to Windows XP. I am looking for a solution that doesn't involve rewriting our application (much) and that allows all our users to keep using Hebrew Regional Settings. To summarize our...
0
2099
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, on which this field is based, is also formatted as short time. When the form opens, everything is OK, the time field shows time as it should. When user clicks in this field to edit it, the field all of a sudden starts showing date 1/01/1900 +...
1
2521
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 date. This works fine and date of birth is entered as month, day, year in standard short date format (99/99/0000;;). Here is the problem, I would also like to print out a list of all clients who have a birthday in any given month. Presently,...
7
8510
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 the Toolbox and then set the Format property appropriately. I have noticed that sometimes the Time format will reset spontaneously to Short Date. I looked at the .rc file and found that the usual form for a Short Date is as follows: CONTROL ...
3
1986
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 service. The COM object isn't mine, and it wants to receive dates in a short date format, and it seems to inherit the localized settings of it's host machine. The machine with that service/COM object is in Canada and is set to use dd/mm/yyyy date format,...
6
2395
by: ABC | last post by:
Is there any function return the short date format on the regional and Language Options under control panel?
2
7015
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 convert all the general date data into short date format, so i would like to delete the time part of the data, it is any way i can do that ???? Thank you in advance and sorry for my english carlos
3
2240
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 dates that are in the database (formatted as above), isolate the date (which is in short format) and compare it to the short formatted date in a datetimepicker.
5
6561
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
9943
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11151
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10750
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10858
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10419
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5804
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4619
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4225
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3237
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.