Path: csiph.com!aioe.org!.POSTED!not-for-mail From: Joao Rodrigues Newsgroups: comp.lang.javascript Subject: Re: new Date().toLocaleTimeString() sponned in Fall Creators Update. UL locale Date: Sat, 6 Jan 2018 13:02:05 -0200 Organization: Aioe.org NNTP Server Lines: 50 Message-ID: References: <9acafc2f-1bc7-442f-adb7-ee34368545a8@googlegroups.com> NNTP-Posting-Host: CRH1ia2SZSbkGzbT8VjbVg.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 Content-Language: en-GB X-Notice: Filtered by postfilter v. 0.8.2 Xref: csiph.com comp.lang.javascript:34485 On 31/12/2017 15:57, Dr J R Stockton wrote: > All of my PCs are set, everywhere that I have found, to > use UK, English, and ISO 8601, including the 24-hour clock. > > JavaScript new Date().toLocaleTimeString() in up-to-date > Windows 7, final Windows XP, and probably in Windows 98 & > maybe even in Windows 3.x, and probably also in previous > Windows 10, gave the 24-hour clock, "HH:MM:SS" > > Today, I allowed a Windows 10 update on my laptop FUJ-2012 > - what arrived was Fall Creators Update, I think. > > In the new update, I get "hh:mm:ss PM". I expect to see > AM tomorrow morning. and an wondering whether the hours > field will have its leading zero before 10:00; I believe > I've seen corresponding ineptitude somewhere in UTC time. > > That is the case in all of the browsers I tested, which > are not all that I have. > > I don't know what happens in other locales, but it seems > likely that Evertjan & others will be able to tell us. > You may use .toLocaleTimeString() with the new locales and options arguments [1]: var date = new Date(); var options = { year: 'numeric', month: 'numeric', day: 'numeric', hour: 'numeric', minute: 'numeric', second: 'numeric', hour12: false, timeZone: 'GMT' // London - UK }; console.log(date.toLocaleTimeString('en-GB', options)); // 06/01/2018, 14:57:25 Or use the Intl object from the ECMAScript Internationalization API [2] directly: console.log(new Intl.DateTimeFormat('en-GB', options).format(date)); [1] [2] Cheers, Joao Rodrigues