如何获取用户在JavaScript
我注意到,使用下面的HTML代码:如何获取用户在JavaScript
<input type="date" value="2017-12-13" />
结果在输入看起来像这样:
但是,我发现没有证据表明我可以使用JavaScript函数手动格式化日期。
这似乎很奇怪,他们提供了这个功能在HTML元素,但在JavaScript中。
作为一种冒险的方法,我研究过只是创建一个输入,禁用它并使用css格式化它看起来像简单的文本。
是否有我不知道使用这种格式的功能,如果没有,是否有任何计划添加此功能。
要想轻松地测试自己,请按照上图中指示的窗口中的格式更改。重新启动谷歌浏览器,然后访问https://jsfiddle.net/3hyyv04d/1/
我认为没有核心功能,你错过了,并在编写时没有计划添加它,因为RFC是关闭了。 此主题具有所有必要的信息:Is there any way to change input type="date" format?
这不是一个答案,它应该是一个评论。您应该将其标记为您所链接问题的重复。 – RobG
类似的问题已答复这里。 How to get the exact local time of client?也在这里How to find the operating system version using JavaScript也How to detect my browser version and operating system using JavaScript?
检测OS:
// This script sets OSName variable as follows:
// "Windows" for all versions of Windows
// "MacOS" for all versions of Macintosh OS
// "Linux" for all versions of Linux
// "UNIX" for all other UNIX flavors
// "Unknown OS" indicates failure to detect the OS
var OSName="Unknown OS";
if (navigator.appVersion.indexOf("Win")!=-1) OSName="Windows";
if (navigator.appVersion.indexOf("Mac")!=-1) OSName="MacOS";
if (navigator.appVersion.indexOf("X11")!=-1) OSName="UNIX";
if (navigator.appVersion.indexOf("Linux")!=-1) OSName="Linux";
document.write('Your OS: '+OSName);
// 2. To know the timezone of the client relative to GMT/UTC here you go:
var d = new Date();
var tz = d.toString().split("GMT")[1].split(" (")[0]; // timezone
var d = new Date();
var tz = d.toString().split("GMT")[1]; // timezone, i.e. -0700 (Pacific Daylight Time)
那就对@RobG。我回答,而不是评论,因为我没有所需的特权。注意到一切。 THKS – Nditah
是中发生的事情,那是因为一些JavaScript的你使用。基本的浏览器代码不会像这样重写日期字符串。 – Pointy
我不确定我是否理解这个问题,你想要一个可以格式化日期对象的函数,就像用户操作系统一样? – MinusFour
@点它发生没有javascript,自己尝试 - 看到https://jsfiddle.net/3hyyv04d/ –