Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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...
Posted
Comments
Thanks7872 6-May-14 8:58am    
It doesnt give you database time. In very simple words, if you deploy your app on server than it will give you time of that system. Whats your exact issue?
Sanket Saxena 6-May-14 9:00am    
There is no way to do it in C#, you have to get the time offset in javascript. Check my solution.
Sergey Alexandrovich Kryukov 6-May-14 10:45am    
Not Datetime.Now, but DateTime.Now. It does not give you the "database time", it gives you system time... on the system where the call is done, server-side in this case.
—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
 
Share this answer
 
 
Share this answer
 
Comments
King Fisher 6-May-14 9:12am    
good one
Abhishek Pant 6-May-14 9:12am    
Thanks for vote
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[^]
 
Share this answer
 
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900