Hi,
It's been a while since I've worked with javascript time comparison,
and I was wondering how I can say "if time < 15:30"?
The semicolon looks out of place to me, and indeed it has caused an
error.
Any help is greatly appreciated.
Thanks
Louis 7 1584
ll wrote:
It's been a while since I've worked with javascript time comparison,
and I was wondering how I can say "if time < 15:30"?
What time?
The semicolon looks out of place to me,
Probably you mean the colon.
and indeed it has caused an error.
Because there is no such thing as a time expression that could have the
syntax you use.
The following is for local time, whenever local (client) time is. If
you need UTC, use getUTC...(), respectively. Note that the client's
clock must be set correctly for that to work, so you should not rely on
it for critical data:
var d = new Date();
if (d.getHours() < 15 || (d.getHours() == 15 && d.getMinutes() < 30))
{
// ...
}
PointedEars
--
var bugRiddenCrashP ronePieceOfJunk = (
navigator.userA gent.indexOf('M SIE 5') != -1
&& navigator.userA gent.indexOf('M ac') != -1
) // Plone, register_functi on.js:16
Try what Thomas said, but if his instructions are somewhat confusing,
use
// if t is a Date object
var d = t;
// otherwise if t is a string like '1:00 pm', this might work
var d = new Date();
d.setTime ( Date.parse ( t ) );
// go on and compare
if (d.getHours() < 15 || (d.getHours() == 15 && d.getMinutes() < 30))
{
// ...
}
On Aug 3, 1:49 pm, jamie...@gmail. com wrote:
Try what Thomas said, but if his instructions are somewhat confusing,
use
// if t is a Date object
var d = t;
// otherwise if t is a string like '1:00 pm', this might work
var d = new Date();
d.setTime ( Date.parse ( t ) );
// go on and compare
if (d.getHours() < 15 || (d.getHours() == 15 && d.getMinutes() < 30))
{
// ...
}
Many thanks, Thomas and Jamie for your help!
both worked seamlessly.
Kind Regards,
Louis ja******@gmail. com wrote:
Try what Thomas said, but if his instructions are somewhat confusing,
use
// if t is a Date object
var d = t;
// otherwise if t is a string like '1:00 pm', this might work
var d = new Date();
d.setTime ( Date.parse ( t ) );
*If* the above works for you, then
var d = new Date(t);
should suffice. ES3 15.9.3.2 specifies the value t to be parsed "in
exactly the same manner as for the parse method (section 15.9.4.2); let
V be the time value for this date."
However, your approach fails in my Firefox 2.0.0.6 and Internet Explorer
7, where it produces NaN for "1:00 pm"; a value of "12/12/2007", for
example, works there. "1:00 pm" works in Opera 9.22, though (and does
exactly the same as your approach). (All on Windows XP, locale de-CH.)
Since I can't find anything specified about it, it would seem that the
accepted string syntax is implementation-dependent and maybe even
locale-dependent. So this approach would be not an interoperable one
and should be avoided.
Please quote the minimum of what you are replying to, as described in
the newsgroup's FAQ notes.
PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not the
best source of advice on designing systems that use javascript.
-- Richard Cornford, <f8************ *******@news.de mon.co.uk>
In comp.lang.javas cript message <11************ **********@22g2 000hsm.goo
glegroups.com>, Fri, 3 Aug 2007 18:49:59, ja******@gmail. com posted:
>// otherwise if t is a string like '1:00 pm', this might work var d = new Date(); d.setTime ( Date.parse ( t ) );
Date.parse("1:0 0 pm") gives NaN in IE6.
>// go on and compare if (d.getHours() < 15 || (d.getHours() == 15 && d.getMinutes() < 30))
The more intelligent and economical programmer might prefer
if (d.getHours()*2 4 + d.getMinutes() < 15*24+30) ...
but they are a rare breed.
--
(c) John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v6.05 IE 6.
Web <URL:http://www.merlyn.demo n.co.uk/- w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demo n.co.uk/programs/- see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Dr J R Stockton wrote:
[...] ja******@gmail. com posted:
>// go on and compare if (d.getHours() < 15 || (d.getHours() == 15 && d.getMinutes() < 30))
The more intelligent and economical programmer might prefer
if (d.getHours()*2 4 + d.getMinutes() < 15*24+30) ...
but they are a rare breed.
The even more intelligent programmer would multiply the hours with 60
(minutes), not 24 (hours) as he would compare against the number of
minutes passed since local midnight.
PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not the
best source of advice on designing systems that use javascript.
-- Richard Cornford, <f8************ *******@news.de mon.co.uk>
In comp.lang.javas cript message <46************ **@PointedEars. de>, Sat,
4 Aug 2007 11:30:34, Thomas 'PointedEars' Lahn <Po*********@we b.de>
posted:
> However, your approach fails in my Firefox 2.0.0.6 and Internet Explorer 7, where it produces NaN for "1:00 pm"; a value of "12/12/2007", for example, works there. "1:00 pm" works in Opera 9.22, though (and does exactly the same as your approach). (All on Windows XP, locale de-CH.)
CH? But 50% of the Swiss are gentlemen.
The form "12/12/2007" can only be recommended for about 3% of dates;
does it mean 12 Dec 2007 or Dec 12 2007? It will not otherwise be taken
as Europeans would wish. The form indicated by "2007/12/25" seems safe
as a new Date() argument, in any location.
>Since I can't find anything specified about it, it would seem that the accepted string syntax is implementation-dependent and maybe even locale-dependent.
Evidently you have not read ISO/IEC 16262 carefully enough.
So this approach would be not an interoperable one and should be avoided.
Your signature separator is misplaced and your signature is both too
long and malformed.
--
(c) John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demo n.co.uk/- FAQish topics, acronyms, & links.
Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)
Do not Mail News to me. Before a reply, quote with ">" or "" (SonOfRFC1036) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Radioactive Man |
last post by:
anyone know of a function like "raw_input", which collects a string
from the user entry, but one where I can set a time limit, as follows:
time_limit = 10 # seconds
user_answer = function_xyz("GIVE ME AN ANSWER: ", time_limit)
The problem with "raw_input" is that it will stop unattended script
indefinitely. I'm looking for a...
|
by: Nick Coghlan |
last post by:
Time for another random syntax idea. . .
So, I was tinkering in the interactive interpreter, and came up with the
following one-size-fits-most default argument hack:
Py> x = 1
Py> def _build_used():
.... y = x + 1
.... return x, y
....
|
by: Polly |
last post by:
I had a macro that ran a parameter query and created and opened an
Excel file with the system date as part of the file name, but I had to
change the file name by hand. So I converted the macro to code using
tools-->references.
The converted macro included the following statement:
DoCmd.OutputTo acQuery, "qselLabelsBloodLog_output",...
|
by: swaroophr |
last post by:
Which of switch statement and if-else statement takes less time to
execute?
|
by: Adam Blair |
last post by:
Is it possible to bind a switch statement to an Enum such that a compile-time
error is raised if not all values within the Enum are handled in the switch
statement? I realise you can use default: to catch unhandled cases, but of
course this is only at run-time.
Example:
public enum MyEnum
{
one, two, three, four
}
| |
by: wxs |
last post by:
Many times we have a bunch of enums we have from either different enums or
the same enum that will have various numeric values assigned. Rarely will
there be collisions in numbering between the enums. These enums you might
imagine would be like OrderPrice=27, OrderQuantity=50, OrderSide=62. There
may be a lot of these. So normally what we...
|
by: OlafMeding |
last post by:
Below are 2 files that isolate the problem. Note, both programs hang
(stop responding) with hyper-threading turned on (a BIOS setting), but
work as expected with hyper-threading turned off.
Note, the Windows task manager shows 2 CPUs on the Performance tab with
hyper-threading is turned on.
Both Python 2.3.5 and 2.4.3 (downloaded from...
|
by: Akinyemi |
last post by:
I created a Database which I named "Address".
I went through the Control Panel and created a DSN to enable me connect to the Database through ODBC.
I then created a Form with the same fields as that of the Database. I wrote the necessary codes and ran the Program. Below are my codes and the runtime error I received:
Run-Time Error...
|
by: DontB3 |
last post by:
Hi, I'm new in this forum, and i hope someone can help.
I'm creating an automatic application that transfer a database from Access -> DBF -> Oracle.
When My App try to execute Insert SQL statement from DBF to Oracle database i found an error like this
{Run-time error "7": Error executing statement! Error: System resource exceeded.}
...
|
by: =?Utf-8?B?VGhlTWFkSGF0dGVy?= |
last post by:
I am very sorry to bring a topic up that has been beaten with an ugly
stick..... but...
If I want to "fix" an byte array for the life time of a program would it be
better allocating it on the unmanaged heap?
Yes I know that if I am to pin the object for long periods of time, that it
would be best to do it at the very initial start of the...
|
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...
| |
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...
|
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...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |