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


Groups > comp.lang.javascript > #18595 > unrolled thread

How do I get current time in hh:mm

Started by"Tony" <tony.johansson@inport.com>
First post2013-02-22 15:52 +0100
Last post2013-02-25 10:04 +0000
Articles 20 on this page of 22 — 12 participants

Back to article view | Back to comp.lang.javascript


Contents

  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

Page 1 of 2  [1] 2  Next page →


#18595 — How do I get current time in hh:mm

From"Tony" <tony.johansson@inport.com>
Date2013-02-22 15:52 +0100
SubjectHow do I get current time in hh:mm
Message-ID<kg80ll$u70$1@dont-email.me>
//tony

[toc] | [next] | [standalone]


#18596

Fromdann90038@gmail.com
Date2013-02-22 14:58 -0800
Message-ID<1a679606-83c6-4dc8-8224-98135cfb4882@googlegroups.com>
In reply to#18595
To tony

var d = new Date();
d.getHours()%12+':'+d.getMinutes();

[toc] | [prev] | [next] | [standalone]


#18598

FromJim T. <x@y.z>
Date2013-02-22 19:06 -0500
Message-ID<3u1gi8h18qd6ik71erdd01i2u328eoekcr@4ax.com>
In reply to#18596
On Fri, 22 Feb 2013 14:58:11 -0800 (PST), dann90038@gmail.com wrote:

>To tony
>
>var d = new Date();
>d.getHours()%12+':'+d.getMinutes();

Not quite. 

[toc] | [prev] | [next] | [standalone]


#18599

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2013-02-23 11:04 +0100
Message-ID<XnsA17070ABE82CDeejj99@194.109.133.133>
In reply to#18598
Jim T. wrote on 23 feb 2013 in comp.lang.javascript:

> On Fri, 22 Feb 2013 14:58:11 -0800 (PST), dann90038@gmail.com wrote:
> 
>>To tony
>>
>>var d = new Date();
>>d.getHours()%12+':'+d.getMinutes();
> 
> Not quite. 

Indeed, that only sort of works for US-of-A-ers.

[and even they would object to "11:8", I suppose.]

The Q was: hh:mm

Please OP, put your Q also in the text, next time,
and include your [failed] effords.

============================
var d = new Date();

document.write(two(d.getHours())+':'+two(d.getMinutes()));

function two(x){
  return (x<10)?'0'+x:''+x;
};
============================


-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [next] | [standalone]


#18603

FromMike Duffy <Use.web.form@website_in_sig.com>
Date2013-02-23 16:44 +0000
Message-ID<XnsA17077826B172Usewebformwebsiteins@94.75.214.39>
In reply to#18599
"Evertjan." <exxjxw.hannivoort@inter.nl.net> wrote in 
news:XnsA17070ABE82CDeejj99@194.109.133.133:


> function two(x){return (x<10)?'0'+x:''+x;};

Why not use sprintf? There are a few free ones available written in 
javscript that seem to work okay. (Warning, most of them are not good at 
handling bad input, like putting the format string as the last arg instead 
of the first, or using umimplemented features, etc.)

HH:mm === sprintf("%02d:%02d", hour, min)

-- 
http://pages.videotron.ca/duffym/index.htm

[toc] | [prev] | [next] | [standalone]


#18605

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2013-02-23 23:39 +0100
Message-ID<XnsA170F0ACC430Aeejj99@194.109.133.133>
In reply to#18603
Mike Duffy wrote on 23 feb 2013 in comp.lang.javascript:

> "Evertjan." <exxjxw.hannivoort@inter.nl.net> wrote in 
> news:XnsA17070ABE82CDeejj99@194.109.133.133:
> 
> 
>> function two(x){return (x<10)?'0'+x:''+x;};
> 
> Why not use sprintf? There are a few free ones 

Free ones of what?

> available written in 
> javscript that seem to work okay. (Warning, most of them are not good
> at handling bad input, like putting the format string as the last arg
> instead of the first, or using umimplemented features, etc.)
> 
> HH:mm === sprintf("%02d:%02d", hour, min)

If that is [from] a library, this NG is about Javascript, why use a library 
for something so simple?



-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [next] | [standalone]


#18615

FromMike Duffy <Use.web.form@website_in_sig.com>
Date2013-02-24 21:38 +0000
Message-ID<XnsA171A9604656CUsewebformwebsiteins@94.75.214.39>
In reply to#18605
"Evertjan." <exxjxw.hannivoort@inter.nl.net> wrote in
news:XnsA170F0ACC430Aeejj99@194.109.133.133: 

> .. why use a library for something so simple?

Because a lot of people have been using "sprintf" for years.

-- 
http://pages.videotron.ca/duffym/index.htm

[toc] | [prev] | [next] | [standalone]


#18617

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2013-02-25 00:16 +0100
Message-ID<XnsA1722D58DC90eejj99@194.109.133.133>
In reply to#18615
Mike Duffy wrote on 24 feb 2013 in comp.lang.javascript:

> "Evertjan." wrote: 
> 
>> .. why use a library for something so simple?
> 
> Because a lot of people have been using "sprintf" for years.

I don't think that is a good enough argument 
to advocate this in a Javascript NG.

sprintf is not part of Javascript.

It is like advocating using a Ferrari to get into bed 
in a NG about pyjamas.

-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [next] | [standalone]


#18604

FromDr J R Stockton <reply1300@merlyn.demon.co.uk.invalid>
Date2013-02-23 21:13 +0000
Message-ID<mRX$$bPHETKRFwbb@invalid.uk.co.demon.merlyn.invalid>
In reply to#18596
In comp.lang.javascript message <1a679606-83c6-4dc8-8224-98135cfb4882@go
oglegroups.com>, Fri, 22 Feb 2013 14:58:11, dann90038@gmail.com posted:

>To tony
>
>var d = new Date();
>d.getHours()%12+':'+d.getMinutes();

Does not always give hh; sometimes just h.
Does not always give mm; sometimes just m.
Cannot tell the difference between morning and afternoon.

Tony : the question should be in the body, without relying on the
Subject.  To post otherwise is a sign of indolence.

You did not say whether you wanted the current time in local or in GMT.

Consider   new Date().toString().match(/..:../) and its variations,
testing with sufficient variation of user locale.

Read <http://www.merlyn.demon.co.uk/js-dates.htm>.

-- 
 (c) John Stockton, nr London, UK.   E-mail, see Home Page.    Turnpike v6.05.
 Website  <http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
 PAS EXE etc. : <http://www.merlyn.demon.co.uk/programs/> - see in 00index.htm
 Dates - miscdate.htm estrdate.htm js-dates.htm pas-time.htm critdate.htm etc.

[toc] | [prev] | [next] | [standalone]


#18607

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2013-02-24 19:37 +0100
Message-ID<1393217.s0XYWeW3uf@PointedEars.de>
In reply to#18596
dann90038@gmail.com wrote:

> To tony

To Tony and dann90038@gmail.com:

This is Usenet; it is not a chat and not a Web forum.  Post accordingly.

1. <http://jibbering.com/faq/#posting>, <http://PointedEars.de/faq#posting>
2. Get a real name.
3. Post only when you are sure (or say when you are not); and when you do
   so, do not use the borken Google Groups.
 
> 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.

-- 
PointedEars

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

[toc] | [prev] | [next] | [standalone]


#18608

FromTim Streater <timstreater@greenbee.net>
Date2013-02-24 18:49 +0000
Message-ID<timstreater-1F577D.18492124022013@news.individual.net>
In reply to#18607
In article <1393217.s0XYWeW3uf@PointedEars.de>,
 Thomas 'PointedEars' Lahn <PointedEars@web.de> wrote:

>    so, do not use the borken Google Groups.

D'ye think you could learn to spell "broken" properly? You've made this 
mistakes enough times now for it to be clear you're doing it on purpose.

-- 
Tim

"That excessive bail ought not to be required, nor excessive fines imposed,
nor cruel and unusual punishments inflicted"  --  Bill of Rights 1689

[toc] | [prev] | [next] | [standalone]


#18609

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2013-02-24 19:56 +0100
Message-ID<2591856.TYeVQcs8cV@PointedEars.de>
In reply to#18608
Tim Streater wrote:

> In article <1393217.s0XYWeW3uf@PointedEars.de>,
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>  Thomas 'PointedEars' Lahn <PointedEars@web.de> wrote:
> 
>>    so, do not use the borken Google Groups.
> 
> D'ye think you could learn to spell "broken" properly? You've made this
  ^^^^                                                               ^^^^
> mistakes enough times now for it to be clear you're doing it on purpose.
  ^^^^^^^^ ^^^^^^^^^^^^
Pot, kettle, black.

<http://catb.org/jargon/html/B/borken.html>
 
-- 
PointedEars

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

[toc] | [prev] | [next] | [standalone]


#18611

FromTim Streater <timstreater@greenbee.net>
Date2013-02-24 19:26 +0000
Message-ID<timstreater-C0B93E.19262624022013@news.individual.net>
In reply to#18609
In article <2591856.TYeVQcs8cV@PointedEars.de>,
 Thomas 'PointedEars' Lahn <PointedEars@web.de> wrote:

> Tim Streater wrote:
> 
> > In article <1393217.s0XYWeW3uf@PointedEars.de>,
> >  Thomas 'PointedEars' Lahn <PointedEars@web.de> wrote:
> > 
> >>    so, do not use the borken Google Groups.
> > 
> > D'ye think you could learn to spell "broken" properly? You've made this
>   ^^^^                                                               ^^^^
> > mistakes
    ^^^^^^^^
This is a mistake.

enough times now for it to be clear you're doing it on purpose.
^^^^^^^^^^^^
This is not.

> <http://catb.org/jargon/html/B/borken.html>

Neither am I interested in childish jargon used by geeks.

-- 
Tim

"That excessive bail ought not to be required, nor excessive fines imposed,
nor cruel and unusual punishments inflicted"  --  Bill of Rights 1689

[toc] | [prev] | [next] | [standalone]


#18614

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2013-02-24 22:30 +0100
Message-ID<1700289.OEO428BxFu@PointedEars.de>
In reply to#18611
Tim Streater wrote:

>  Thomas 'PointedEars' Lahn <PointedEars@web.de> wrote:
>> Tim Streater wrote:
>> > In article <1393217.s0XYWeW3uf@PointedEars.de>,
>> >  Thomas 'PointedEars' Lahn <PointedEars@web.de> wrote:
>> > 
>> >>    so, do not use the borken Google Groups.
>> > 
>> > D'ye think you could learn to spell "broken" properly? You've made this
>>   ^^^^                                                               ^^^^
>> > mistakes
>     ^^^^^^^^
> This is a mistake.

You don't say.

> enough times now for it to be clear you're doing it on purpose.
> ^^^^^^^^^^^^
> This is not.

It does not sound right to me.  I think that “often enough” would be proper 
English instead.  But I am not a native speaker of English, which 
contributes to the possibility that I might be wrong about this.
 
>> <http://catb.org/jargon/html/B/borken.html>
> 
> Neither am I interested in childish jargon used by geeks.

The only thing you appear to be interested in here is trolling.  Go away.

-- 
PointedEars

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

[toc] | [prev] | [next] | [standalone]


#18616

FromTim Streater <timstreater@greenbee.net>
Date2013-02-24 23:00 +0000
Message-ID<timstreater-7CBCB0.23001424022013@news.individual.net>
In reply to#18614
In article <1700289.OEO428BxFu@PointedEars.de>,
 Thomas 'PointedEars' Lahn <PointedEars@web.de> wrote:

> > enough times now for it to be clear you're doing it on purpose.
> > ^^^^^^^^^^^^
> > This is not.
> 
> It does not sound right to me.  I think that “often enough” would be proper 
> English instead.  But I am not a native speaker of English, which 
> contributes to the possibility that I might be wrong about this.

They are about equivalent. Neither is slang, nor regional speech (either 
within the UK or in a more global sense), and there are no class-based 
connotations attached to either. "Often enough" is perhaps slightly 
sharper, but that's all.

You have a very good grasp of English word order, Thomas, I'll give you 
that. I remember studying German more than 50 years ago now, so I have 
some idea of the differences.

-- 
Tim

"That excessive bail ought not to be required, nor excessive fines imposed,
nor cruel and unusual punishments inflicted"  --  Bill of Rights 1689

[toc] | [prev] | [next] | [standalone]


#18610

FromAnders Wegge Keller <wegge@wegge.dk>
Date2013-02-24 19:59 +0100
Message-ID<87sj4lo7vo.fsf@huddi.jernurt.dk>
In reply to#18608
Tim Streater <timstreater@greenbee.net> writes:

> In article <1393217.s0XYWeW3uf@PointedEars.de>,
>  Thomas 'PointedEars' Lahn <PointedEars@web.de> wrote:
> 
> >    so, do not use the borken Google Groups.
> 
> D'ye think you could learn to spell "broken" properly? You've made this 
> mistakes enough times now for it to be clear you're doing it on purpose.

 I'm pretty sure that the deliberate mis-spelling is made to
strengthen the adjective. In case of of GG, it's well-placed.

 See <http://www.faqs.org/docs/jargon/B/borken.html>

-- 
/Wegge

Leder efter redundant peering af dk.*,linux.debian.*

[toc] | [prev] | [next] | [standalone]


#18612

FromRichard Yates <richard@yatesguitar.com>
Date2013-02-24 12:35 -0800
Message-ID<jbuki81g5tn03q3vg7rh8vg7h1t8c2iv70@4ax.com>
In reply to#18607
On Sun, 24 Feb 2013 19:37:27 +0100, Thomas 'PointedEars' Lahn
<PointedEars@web.de> wrote:

>dann90038@gmail.com wrote:
>
>> To tony
>
>To Tony and dann90038@gmail.com:
>
>This is Usenet; it is not a chat and not a Web forum.  Post accordingly.
>
>1. <http://jibbering.com/faq/#posting>, <http://PointedEars.de/faq#posting>
>2. Get a real name.
>3. Post only when you are sure (or say when you are not); and when you do
>   so, do not use the borken Google Groups.
> 
>> 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

[toc] | [prev] | [next] | [standalone]


#18613

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2013-02-24 22:23 +0100
Message-ID<8869854.9U5oQ9T6jY@PointedEars.de>
In reply to#18612
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.

[toc] | [prev] | [next] | [standalone]


#18621

FromRichard Yates <richard@yatesguitar.com>
Date2013-02-24 20:40 -0800
Message-ID<cpqli8l4dm5f1bcfifhjcg3sttt9h5osjj@4ax.com>
In reply to#18613
On Sun, 24 Feb 2013 22:23:41 +0100, Thomas 'PointedEars' Lahn
<PointedEars@web.de> wrote:

>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.

Turing test fail.

[toc] | [prev] | [next] | [standalone]


#18622

FromAndrew Poulos <ap_prog@hotmail.com>
Date2013-02-25 16:17 +1100
Message-ID<mOudnSVIoI6UabfMnZ2dnUVZ_oKdnZ2d@westnet.com.au>
In reply to#18621
On 25/02/2013 3:40 PM, Richard Yates wrote:
> On Sun, 24 Feb 2013 22:23:41 +0100, Thomas 'PointedEars' Lahn
> <PointedEars@web.de> wrote:
>
>> 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.
>
> Turing test fail.

PE showed you where you were wrong. That's ok as PE knows more than the 
average and he's provided you with an opportunity to learn so why do you 
throw insults?

Andrew Poulos

[toc] | [prev] | [next] | [standalone]


Page 1 of 2  [1] 2  Next page →

Back to top | Article view | comp.lang.javascript


csiph-web