在不同的浏览器输入时间字段显示以不同的格式 [英] In different browsers input time field shows in different formats

查看:947
本文介绍了在不同的浏览器输入时间字段显示以不同的格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个输入时间的HTML元素,这一行:

I have created an input time HTML element, with this line:

<input type="time" id="startTime" value="@DateTime.Now.ToString("HH:mm")" />

我使用 C#剃须刀语法,但它其实并不重要。

I am using C# Razor syntax, but it does not really matter.

我检查两个谷歌Chrome和的Mozilla Firefox和在时间重新以24小时格式psented $ P $。后来,当我分享了code。与我的同事们,在他们​​的的Chrome版本的时间重新在上午和下午的12小时格式psented $ P $。是否有指定的方式我的 HTML code那个时候应该重新presented以某种方式在所有浏览器。

I checked it in both Google Chrome and Mozilla Firefox and in both time is represented in 24 hour format. Later, when I shared the code with my colleagues, in their versions of Chrome the time is represented in 12-hour format with AM and PM. Is there a way to specify in my HTML code that time should be represented in one way in all browsers.

有类似的问题这里,但却有人问3年以前,接受的答案开头:

There is similar question here, but however it was asked 3 years ago and the accepted answer starts with:

此功能还处于草案。每个浏览器显示不同的看法。

This feature is still in draft. Each browser shows it differently.

所以我想,如果这个问题已经在此期间得到解决。如果没有,好时机部件的任何建议,欢迎。浮现在我的脑海里最简单的方法是使用单独的选择标签,但我会preFER要使用的包装既小时和分钟单个组件。

so I am wondering if that issue has been resolved in the meantime. If not, any suggestions of good time components are welcome. The simplest way that comes to my mind is to use separate select tags, but I would prefer to use single component which wraps both hours and minutes.

编辑:
我意识到这个问题是与机器的本地设置浏览器中运行,并在我的同事的笔记本电脑在更改设置后,它工作正常。我想知道如果有一种方法来强制所有的浏览器在相同的格式来显示时间,没有机器的设置问题。我用这些字段在几个地方,所以我会preferably坚持给他们,而不是使用不同的HTML组件(因为我不想让我的code太多的变化)。我注意到另一个问题是,输入时间字段是不是像在Mozilla下拉列表(在Chrome的是下拉菜单等)。

I realized the problem is with the local settings of the machine the browser runs on, and after changing the settings on my colleagues' laptops it works fine. I am wondering if there is a way to force all browsers to show time in same format, no matter of the machine's settings. I use those fields in several places, so I would preferably stick to them and not using different HTML components (because I don't want to make too many changes in my code). Another problem I noticed is that the input time field is not like a drop-down list in Mozilla (and in Chrome it is drop-down like).

不久,现在的问题是:如何使用输入时间字段,并迫使他们表现出相同格式的时间在所有浏览器上的时间设置无论机器正在运行上

Shortly, the question now would be: How can I use input time fields and force them to show time in same format in all browsers, no matter on the time settings of the machine they are running on.

感谢您!

推荐答案

这是不相关的浏览器,但对系统的设置。

It is not related to the browser, but to the system settings.

INPUT TYPE =时间显示时间取决于在系统上定义的区域设置

input type="time" displays the time depending on the regional settings that are defined on the system.

这同样适用于日期。

我如何使用输入时间字段,并强迫他们在展示的同时
  在所有浏览器格​​式,在时间设置无论

How can I use input time fields and force them to show time in same format in all browsers, no matter on the time settings

有许多不同的解决方案。最常用的是输入类型=文本。也有jQuery插件,可以搞定。应用广泛的一个JS库是 moment.js

There are plenty of different solutions. The most used is a input type="text". There are also JQuery plugins that can handle that. A js library widly used is moment.js

这篇关于在不同的浏览器输入时间字段显示以不同的格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆