Click here to Skip to main content
15,894,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When I run my application on local host I get my system time and date from DateTime.Now.
But when I hosted it on server I am getting the server Date Time. It is Godaddy server.(USA). instead of server datetime I want to retrieve the machine time and date

What I have tried:

DateTime dateValue = DateTime.Now;
dateValue.ToString("dddd");
+dateValue.ToString("h:mm:ss tt");
Posted
Updated 1-Oct-16 8:35am
Comments
[no name] 1-Oct-16 13:43pm    
Then write some CLIENT side code to get the time.

1 solution

Basically there are two approaches-
1. Client side approach
With this approach you can take help of some client script like javascript to get the date and time on the client system. Something like following-
JavaScript
var currentdate = new Date();

Check following link-
JavaScript Dates[^]

Ok. Now what if I have wrong time set in my computer? Wrong result to expect. That's where we need the second option.
2. Convert the time to local
Well, you can do this with your C# code.
Example:
C#
DateTime dateValue = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, TimeZoneInfo.FindSystemTimeZoneById("India Standard Time")); //for converting to IST


Hope, it helps :)
Note: There are ways to do this in client side too. but these 2 options should help your cause. Please let me know in case I am missing something here.
 
Share this answer
 
Comments
Member 12770464 1-Oct-16 15:22pm    
Okay I will check it and let you know. Meanwhile in my SqlCommand I am using GETDATE() to store datetime in Database. Again the server is hosted on Godaddy.
So that will again use the server datetime or system.
And if suppose it uses server datetime. Can I use this method to get the task done?
Thanks
Member 12770464 1-Oct-16 15:24pm    
@Suvendu. The clients are from different countries. They have different GMT. How to do now.
Suvendu Shekhar Giri 1-Oct-16 15:29pm    
Yes, you can send the datetime value to the DB so that correct value is saved.
Getdate() will return local time.
You do something like
getutcdate()+'5:30'
to get correct value in IST.
Member 12770464 1-Oct-16 15:33pm    
Thats the thing. different user have different UTC. I am looking to make things so that I can use this code .
Karthik_Mahalingam 3-Oct-16 1:09am    
5

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