Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #18613

Re: How do I get current time in hh:mm

Message-ID <8869854.9U5oQ9T6jY@PointedEars.de> (permalink)
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Organization PointedEars Software (PES)
Date 2013-02-24 22:23 +0100
Subject Re: How do I get current time in hh:mm
Newsgroups comp.lang.javascript
References <kg80ll$u70$1@dont-email.me> <1a679606-83c6-4dc8-8224-98135cfb4882@googlegroups.com> <1393217.s0XYWeW3uf@PointedEars.de> <jbuki81g5tn03q3vg7rh8vg7h1t8c2iv70@4ax.com>

Show all headers | View raw


Richard Yates wrote:

> […] Thomas 'PointedEars' Lahn wrote:
>> dann90038@gmail.com wrote:
>>> var d = new Date();
>>> d.getHours()%12+':'+d.getMinutes();
>>
>> Wrong.  This will result in a false 12-hour format (there is no zero hour
>> in the real format) where hours and minutes do not have the leading zero
>> that a>>“hh:mm” format would require.  Also, nobody said that a 12-hour
>> format would be wanted.
> 
> http://www.yatesguitar.com/misc/coder.jpg

Did you even understand a word I wrote?  Go away.

FWIW: A 12-hour time format can be achieved by starting with

  (d.getHours() % 12) || 12

because the remainder 0 (zero) is converted to boolean “false”, and all 
other remainders to boolean “true”.  When the first operand in a 
/LogicalORexpression/ is converted to “false”, the result of the operation 
and the /LogicalORExpression/ is the second operand [1].

“a.m.”/“p.m.” needs to be handled separately, though, and this would still 
not answer what was “asked” here.  However, the actual question that should 
have been asked is too trivial and too often discussed to deserve further 
consideration (“How can I get a number with a leading zero?”).

_________
[1] <http://www.ecma-international.org/ecma-262/5.1/#sec-11.11>
-- 
PointedEars

Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

How do I get current time in hh:mm "Tony" <tony.johansson@inport.com> - 2013-02-22 15:52 +0100
  Re: How do I get current time in hh:mm dann90038@gmail.com - 2013-02-22 14:58 -0800
    Re: How do I get current time in hh:mm Jim T. <x@y.z> - 2013-02-22 19:06 -0500
      Re: How do I get current time in hh:mm "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-02-23 11:04 +0100
        Re: How do I get current time in hh:mm Mike Duffy <Use.web.form@website_in_sig.com> - 2013-02-23 16:44 +0000
          Re: How do I get current time in hh:mm "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-02-23 23:39 +0100
            Re: How do I get current time in hh:mm Mike Duffy <Use.web.form@website_in_sig.com> - 2013-02-24 21:38 +0000
              Re: How do I get current time in hh:mm "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-02-25 00:16 +0100
    Re: How do I get current time in hh:mm Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid> - 2013-02-23 21:13 +0000
    Re: How do I get current time in hh:mm Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-02-24 19:37 +0100
      Re: How do I get current time in hh:mm Tim Streater <timstreater@greenbee.net> - 2013-02-24 18:49 +0000
        Re: How do I get current time in hh:mm Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-02-24 19:56 +0100
          Re: How do I get current time in hh:mm Tim Streater <timstreater@greenbee.net> - 2013-02-24 19:26 +0000
            Re: How do I get current time in hh:mm Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-02-24 22:30 +0100
              Re: How do I get current time in hh:mm Tim Streater <timstreater@greenbee.net> - 2013-02-24 23:00 +0000
        Re: How do I get current time in hh:mm Anders Wegge Keller <wegge@wegge.dk> - 2013-02-24 19:59 +0100
      Re: How do I get current time in hh:mm Richard Yates <richard@yatesguitar.com> - 2013-02-24 12:35 -0800
        Re: How do I get current time in hh:mm Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-02-24 22:23 +0100
          Re: How do I get current time in hh:mm Richard Yates <richard@yatesguitar.com> - 2013-02-24 20:40 -0800
            Re: How do I get current time in hh:mm Andrew Poulos <ap_prog@hotmail.com> - 2013-02-25 16:17 +1100
              Re: How do I get current time in hh:mm Richard Yates <richard@yatesguitar.com> - 2013-02-25 10:45 -0800
      Re: How do I get current time in hh:mm John G Harris <niam@jghnorth.org.uk.invalid> - 2013-02-25 10:04 +0000

csiph-web