如何获取客户端系统日期和时间格式 [英] How Do I Get Client System Date And Time Format

查看:398
本文介绍了如何获取客户端系统日期和时间格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我需要获取客户端系统的日期和时间格式.目前,在我的Web应用程序(使用C#语言在asp.net中开发)中,我要求用户登录到应用程序时必须将日期和时间格式视为其本地PC日期和时间格式设置.

例如,他正在从服务器访问站点,然后能够准确查看其本地系统日期和时间格式,而不是服务器格式.我们通过使用date.toLocaleDateString()尝试了这种方法,但这将返回当前的本地系统日期而不是格式.即使date.toLocalDateString()在不同的浏览器中的行为也不同.

如何获得客户端系统的确切自定义日期和时间格式?
例如:喜欢(dd/MM/yyyy hh:mm,MM/dd/yyyy hh:mm等).
我期望什么:
http://screencast.com/t/pqFxfFWqTZgX [

Hi,

I need to get client system date and time format. At present in my web application (developed in asp.net using C# language) I have requirement when user login into the application they have to see the date and time format as his local PC date and time format setting.

For example, he is accessing the site form the server and then he able to see exact his local system date and time format instead of server format. We tried this approach by using date.toLocaleDateString(), but this is returning the current local system date instead of format. Even date.toLocalDateString() is behaving differently in different browsers.

How do I get exact customize date and time format of client system?
Example: like (dd/MM/yyyy hh:mm, MM/dd/yyyy hh:mm and so on).
What I''m expecting:
http://screencast.com/t/pqFxfFWqTZgX[^]

推荐答案

请参见MSDN [
See MSDN "How to: Display Localized Date and Time Information to Web Users"[^]


没有任何功能可以向您显示操作系统的设置-出于安全原因,这些设置对您不利...
正如您已经发现的那样,实际值取决于浏览器的实现(但是可以通过现代浏览器中的语言环境和选项来控制)...
如果您想在浏览网站时给人以家的感觉,请使用toLocalDateString而不带任何其他选项并且不要害怕,大多数用户不会只是出于娱乐目的而切换浏览器,如果他们习惯了...
如果您希望使用相同的显示格式,则可以根据需要设置字符串格式,并保留操作系统设置(无论如何也无法获得它们)...
There is no function can reveal you the settings of the OS - these are shield from you for security reasons...
As you already spotted the actual value depends on the browser''s implementation (however can be controlled via locale and options in modern browsers)...
If you want to give the feel of home while browsing your site use toLocalDateString without extra options and do not afraid, most users do not switch browser just for fun, and if do they will got accustomed to it...
If you want the same display format, then format your string as you wish and left the OS settings alone (anyway you can not get them)...


这篇关于如何获取客户端系统日期和时间格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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