2017-10-05 66 views
-1
操作系統首選日期和時間格式

我注意到,使用下面的HTML代碼:如何獲取用戶在JavaScript

<input type="date" value="2017-12-13" /> 

結果在輸入看起來像這樣:

enter image description here

此格式與Windows格式配置一致: enter image description here

但是,我發現沒有證據表明我可以使用JavaScript函數手動格式化日期。

這似乎很奇怪,他們提供了這個功能在HTML元素,但在JavaScript中。

作爲一種冒險的方法,我研究過只是創建一個輸入,禁用它並使用css格式化它看起來像簡單的文本。

是否有我不知道使用這種格式的功能,如果沒有,是否有任何計劃添加此功能。

要想輕鬆地測試自己,請按照上圖中指示的窗口中的格式更改。重新啓動谷歌瀏覽器,然後訪問https://jsfiddle.net/3hyyv04d/1/

+0

是中發生的事情,那是因爲一些JavaScript的你使用。基本的瀏覽器代碼不會像這樣重寫日期字符串。 – Pointy

+0

我不確定我是否理解這個問題,你想要一個可以格式化日期對象的函數,就像用戶操作系統一樣? – MinusFour

+0

@點它發生沒有javascript,自己嘗試 - 看到https://jsfiddle.net/3hyyv04d/ –

回答

1

我認爲沒有核心功能,你錯過了,並在編寫時沒有計劃添加它,因爲RFC是關閉了。 此主題具有所有必要的信息:Is there any way to change input type="date" format?

+1

這不是一個答案,它應該是一個評論。您應該將其標記爲您所鏈接問題的重複。 – RobG

1

類似的問題已答覆這裏。 How to get the exact local time of client?也在這裏How to find the operating system version using JavaScriptHow 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) 

+0

那就對@RobG。我回答,而不是評論,因爲我沒有所需的特權。注意到一切。 THKS – Nditah

相關問題