473,396 Members | 1,927 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,396 software developers and data experts.

DateRangeSelector using milliseconds

Hi, i've found this DateRangeSelector :
http://www.petrafex.com/view/pgID/21...tor_date_manip
ulation__dates_.html . This works fine but i need it to send the dates as :
yyyy-mm-dd or dd-mm-yyyy instead of the milliseconds it using now. I also
want to get rid of the 'show calender' pop-ups, i just need the Date Range
Selector dropdowns. There is a demo and a download.

I'm a newbie to javascript, so can someone please show how this javascript
needs to be changed so i can use this the way i decribed.

Thanks in advance, RCAV
Jul 23 '05 #1
6 1715
Jc
If the component returns the date as milliseconds, that is the proper
way to do it, you don't want it to return a string in some format,
unless there is an option for the date range selector to take a date
format string.

When working with dates, all of the passing around of a date should be
formatless internally, and only converted to an actual date string when
presented to the user.

If you are given a date as milliseconds and you want to present it to
the user in some specific format, you can pass the milliseconds into
the Date object constructor and then use the Date object methods to
retrieve the various date parts and combine them as desired to create
the date string.

var dtDate = new Date(123456789);
var sMonth = dtDate.getMonth();

Just remember that how the user reads a date string is locale
dependent, for example, if I saw 01/02/2004 I would have no idea if
that was referring to Jan 2 or Feb 1 unless I knew the date format
string for that date (ie mm/dd/yyyy or dd/mm/yyyy).

Milliseconds is an unambiquous way to represent a time, and should be
used for everything such as date storage, date comparison, etc. Note
that Javascript does not have a way to create a date from a combination
of a milliseconds from 1970 value and a windows format string, so
you'll have to either use a single date format for presentation, or do
something fancier and allow the user to choose from a list of
predefined date formats, or even type one in, although that would by
the most complicated since you would have to interpret the date format
string yourself.

Basically, all you have to remember when working with dates is to use a
formatless way to represent the time internally. Stop and refactor your
code if you ever see yourself doing something like:

var dtDate = new Date("01/02/2004");

Since javascript runs on the client, the date string will be
interpreted according to the current windows regional settings on the
client computer. This means that the code will create two different
dates when executed on computers with sufficiently different regional
settings, for example, a computer in Europe and a computer in the US.

Jul 23 '05 #2
JRS: In article <10**********************@z14g2000cwz.googlegroups .com>
, dated Sun, 31 Oct 2004 12:35:58, seen in news:comp.lang.javascript, Jc
<go****@weinrichs.com> posted :
Basically, all you have to remember when working with dates is to use a
formatless way to represent the time internally. Stop and refactor your
code if you ever see yourself doing something like:

var dtDate = new Date("01/02/2004");

Since javascript runs on the client, the date string will be
interpreted according to the current windows regional settings on the
client computer. This means that the code will create two different
dates when executed on computers with sufficiently different regional
settings, for example, a computer in Europe and a computer in the US.


That's over-optimistic. Language specifications do not require regional
settings to be considered, and one cannot rely on all browsers to do so,
or to do so correctly. Moreover, the operating system may not get all
regional settings right for the region chosen.

It's also naive; systems not running Windows do not have current Windows
regional settings.

And an absolute time, such as milliseconds GMT, does not define a civil
date; while New Zealanders are ready to start Christmas lunch, it's
still Christmas Eve afternoon in Hawaii.

--
© 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 #3
Jc
John, your critique of my response to Richard necessitates further
explanation, as you seem to have several misconceptions regarding dates
and javascript.

Javascript DOES consider regional dependant settings, such as the
toLocaleString method of the Date object, which returns a date
converted to a string using the current locale. It is the
responsibility of the Javascript implementation to deal with the
operating system regional settings, which means programmer's CAN rely
on the regional features of javascript within a browser setting.

What exactly is naive? Are you implying that there is an OS in popular
use that doesn't offer regional settings in its configuration which are
taken into consideration by its scripting implementation? Or are you
simply stating the obvious fact that the regional settings of a
non-Windows OS would be called something other than "Windows regional
settings"?

If you have a better suggestion or even a pointer to a resource that
addresses Richard's question, let's hear it.

Your comment regarding milliseconds GMT indicates a lack of
understanding of GMT, or more precisely, UTC (Universal Coordinated
Time). Of course it doesn't refer to the same local time for every time
zone... that's the whole point of it being "absolute". A number of
milliseconds UTC is absolute, therefore it refers to the exact same
point in time regardless of location. This is desireable, because in
the situation you described, the time would easily be adjusted (before
being displayed) to the region's local time by determining the client's
offset from UTC (using another method of the Date object,
getTimezoneOffset).

You do NOT want to store the time as milliseconds relative to the
region's timezone, this is convoluted, because now you have to not only
store the relative time, but also the timezone that it is relative from
and also whether the region was in daylight savings time (which
unfortunately isn't even available from javascript). Using UTC
(milliseconds or full-string representation) gives the programmer an
unambiguous time to work with internally and for storage.

On a side note, referring to GMT in technical context should be
avoided, the more precise term is UTC.

Jul 23 '05 #4
JRS: In article <10**********************@z14g2000cwz.googlegroups .com>
, dated Tue, 2 Nov 2004 21:06:12, seen in news:comp.lang.javascript, Jc
<go****@weinrichs.com> posted :
John, your critique of my response to Richard necessitates further
explanation, as you seem to have several misconceptions regarding dates
and javascript.
Please learn to quote correctly when replying, with an adequate
attribution and responses following quoted points.
Javascript DOES consider regional dependant settings, such as the
toLocaleString method of the Date object, which returns a date
converted to a string using the current locale. It is the
responsibility of the Javascript implementation to deal with the
operating system regional settings, which means programmer's CAN rely
on the regional features of javascript within a browser setting.
Do not assume that javascript always correctly implements that
responsibility. It does not.

Do not assume that the data selected by the regional settings of, for
example, Windows always actually matches the real world. It does not.

Remember also that nowadays, with portable PCs being used by naive
travellers, it is quite likely that a change of local time will in fact
be done as a clock correction rather than as a zone change; the regional
settings may well be for a different region.
What exactly is naive?
Your explicit assumption that the OS is windows.

Your comment regarding milliseconds GMT
...

You do NOT want to store the time as milliseconds
...
ISTM that you should have understood what I wrote *before* responding.

Sometimes, for example when considering astronomical events, one
definitely wants an absolute date/time, independent of location. But
sometimes, for example when considering historical events, one by custom
wants a local date, for the current location.

For example, IIRC Arnie the unspellable was, IIRC, born in Europe
(Austria?), on a known (by him) date Y M D. No doubt he celebrates his
N'th birthday on Californian Y+N M D, rather than at the time, about
half a day earlier, matching the Austrian date.

On a side note, referring to GMT in technical context should be
avoided, the more precise term is UTC.


(a) The legal time in the UK is GMT.

(b) UTC has leap seconds; javascript does not. In fact very few
computers understand UTC properly. Therefore, GMT is a better
description of what is actually implemented. While computers may be
frequently corrected by reference to a UTC clock, their uncertainty in
maintaining time is generally large in comparison with the UTC/GMT
difference (at most 0.9 seconds). UT would be a better term, except
that most readers would take it as being a typo for UTC, or short for
Utah.
Perhaps you should read the newsgroup FAQ - all of it.

--
© 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 #5
Jc
Well, I'm glad you took the time to read up on the topic before
replying this time, if only to criticize the format of my post.

Your paranoia about using regional settings in javascript is a personal
preference at best, I don't think it is fair to discredit techniques
for making a best effort at displaying date/times properly because you
apparently know of some unstated OS/browser which provides inaccurate
regional information.

I have no qualms assuming that the regional information provided
through the javascript date object is as accurate as is attainable
through javascript. As always, if you know of a better way, let's hear
it. There is no argument from me regarding the fact that there would be
an issue if the user expects the script to accurately display dates
when the regional settings of his computer are skewed from the "real
world", whether intentionally or not. It is outside the scope of
javascript to attempt to compensate for such things.

The rest of your discussion of which countries use GMT, leap seconds,
and clock accuracy is also irrelevant, and I won't waste anyone's time
discussing it. Javascript does not "keep time", that is performed by an
external entity. It is well documented that javascript supports UTC and
has backwards compatibility for GMT, refer to documentation on the Date
object's methods.

I suspect the reason for your negative attitude towards my post stems
from your personal dislike of the windows operating system, which I
passingly referenced in my original post. My post was not dependant on
the OS being windows, the techniques described are OS independent, so
let's not get bent out of shape about it and start insulting each
other's intelligence. If it makes you feel better, let's call the
regional settings "OS regional settings" instead, to account for any
minority operating systems you're particular to.

Jul 23 '05 #6
JRS: In article <10**********************@c13g2000cwb.googlegroups .com>
, dated Wed, 3 Nov 2004 22:24:17, seen in news:comp.lang.javascript, Jc
<go****@weinrichs.com> posted :
Please learn, and use, the correct way of replying, with adequate
attributions and quotes. Others can; why not you? It is an established
and agreed Usenet standard, after all.
It is well documented that javascript supports UTC and
has backwards compatibility for GMT, refer to documentation on the Date
object's methods.


Never assume that those who write documentation actually understand what
they are writing about. If javascript truly supported UTC-the-
timescale, it would have provision for leap seconds. It does support
UTC-the-acronym.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME ©
Web <URL:http://www.uwasa.fi/~ts/http/tsfaq.html> -> Timo Salmi: Usenet Q&A.
Web <URL:http://www.merlyn.demon.co.uk/news-use.htm> : about usage of News.
No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.
Jul 23 '05 #7

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

Similar topics

2
by: Kevin Thomas | last post by:
Hello, I have a date value in a table SQL Server database that looks like this: 2005-10-11 12:54:36.860 When I load the record into a dataset in VB.NET and retrieve the date value into code,...
26
by: Pravesh | last post by:
Hi: is there a way to get current system time in milliseconds... which functions and headers?? thanks pravesh
2
by: Daniel | last post by:
how to get the number of milliseconds between two System.DateTime objects
9
by: HL | last post by:
I am using VS 2005 Beta - C# Problem: The Timer fires a few milliseconds before the actual Due-Time Let's say a timer is created in the following manner: System.Threading.Timer m_timer = null;...
2
by: Harlin Seritt | last post by:
How can I take a time given in milliseconds (I am doing this for an uptime script) and convert it to human-friendly time i.e. "4 days, 2 hours, 25 minutes, 10 seonds."? Is there a function from the...
13
by: Sharon | last post by:
I need to test a performance of some code of mine. I tried using the Environment.TickCount but its resolution is too low (from the MSDN remarks: The resolution of the TickCount property cannot be...
4
by: Deniz Dogan | last post by:
Hello. I need help with a small problem I'm having. I want to make a function which takes an integer representing some time in milliseconds and returns the same time but formatted as...
6
by: Manikandan | last post by:
Hi, I need to insert the datetime with milliseconds value into a datarow. My code as below DataTable testDataTable=new DataTable(); testDataTable.Columns.Add("updatedDateTime",...
1
by: ndedhia1 | last post by:
I was reading in a log file like this that had no milliseconds: QuoteBlockTiming exceeded 1 ms: 1 --- Thu Dec 10 02:01:40 CST 2009 170.137.15.155 Class key = 601650761 block size QuoteBlockTiming...
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:
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.