获取当前系统时间 [英] To get Current sytem time

查看:79
本文介绍了获取当前系统时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好..



我希望代码能够在不使用任何第三方工具的情况下获得当前的系统时间。我正在使用Datetime.Now,但它提供当前的数据库时间..但我想要当前的PC时间..



请帮帮我...







提前致谢...

Hi Everyone..

i want code for to get current system time with out any using third party tool. i am using "Datetime.Now" but it gives current database time.. but i want current PC time..

please help me...



Thanks in advance...

推荐答案

请看我对这个问题的评论。你真的需要当前的系统时间,但当然是在服务器端。如果你担心的是时间转移,你总是可以通过调用属性来统一时间 System.DateTime.UtcNow

http://msdn.microsoft.com/en-us/library/system.datetime.utcnow.aspx [ ^ ] 。



这样,您就可以为所有客户获得同步时间。要在客户端显示时间,您可以获取当前时区偏移量( getTimezoneOffset())并显示本地时间。例如,参见:

http://stackoverflow.com/questions/2263705/display-local-time-from-utc-time-stored-in-sql-database-on-asp-net-app [ ^ ],

http://stackoverflow.com/questions/6525538/convert-utc-date-time-to-local-date-time-using-javascript [< a href =http://stackoverflow.com/questions/6525538/convert-utc-date-time-to-local-date-time-using-javascripttarget =_ blanktitle =New Window> ^ ]。



这是另一种方法,但在很多情况下,这正是需要的。



-SA
Please see my comment to the question. You really take the current system time, but on the server side, of course. If your concern is the time shift, you can always take unified time by calling the property System.DateTime.UtcNow:
http://msdn.microsoft.com/en-us/library/system.datetime.utcnow.aspx[^].

This way, you can get synchronized time for all your clients. To display time on client side, you can get the current timezone offset (getTimezoneOffset()) and display local time. See, for example:
http://stackoverflow.com/questions/2263705/display-local-time-from-utc-time-stored-in-sql-database-on-asp-net-app[^],
http://stackoverflow.com/questions/6525538/convert-utc-date-time-to-local-date-time-using-javascript[^].

This is the alternative approach, but in many cases this is exactly what is needed.

—SA


使用javascript获取日期 [ ^ ]


你可以在c#中使用DateTime.Now,



如果它是Windows应用程序它将给出机器的日期,但在Web应用程序中它将是五个服务器的日期。



要在web应用程序中使用javascript来获取客户端机器的日期时间并将其传递给webmethod以进一步使用它



http://runnable.com/UhKwAWqqRscRAADQ/retrieve-client-s-today-s-date-using-asp-net [ ^ ]
you can use DateTime.Now in c#,

if it is windows application it will give machine's date, but in web application it will five server's date.

to do in web application use javascript to get client machine's date time and pass it to webmethod to use it further

http://runnable.com/UhKwAWqqRscRAADQ/retrieve-client-s-today-s-date-using-asp-net[^]


这篇关于获取当前系统时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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