Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

date / time management - c#, asp.net 2.x, iis 6.0, vs studio pro

Posted on 2007-11-18
10
Medium Priority
?
987 Views
Last Modified: 2013-12-17
The issues of timezones has crept into my programming requirements as server sits in a different timezone compared to users for example.  As a result, when posting record updates or anything relating to date and time, these are out of sync.

I am using the following script for example to gather to current date:

Label_Date.Text = DateTime.Now.ToString("ddd, MMM dd, yyyy");

I suspect this is gathering the date locally - if so, how do I collect the current date and time from the server?  (so then can sync up to the correct date/time zone locally depending on users location etc).

How are daylight saving worked out (in terms of keeping this uptodate and current, and in particular during that day of changing the clock back ro forward -- how you account for a loss or gain of an hour for example in the server logs/online form processing etc) -- as different countries have varying approaches to this.

The main thing I would like to resolve firstly, is gathering the latest date/time from the server (not via local o/s).

Thank you in advance for your time and efforts with this enquiry.
0
Comment
Question by:amillyard
  • 7
  • 3
10 Comments
 
LVL 15

Expert Comment

by:Solar_Flare
ID: 20309749
if network traffic is not an issue and the clients are always online you could expose a simple web service on your server that has a GetCurrentTime function that provides the server's time - the clients could then ask for the servers time when needed.

alternatively if you rely on the time on the clients always being configured correctly you could use universal time for everything
Dim now As DateTime = DateTime.Now
Dim nowGMT As DateTime = now.ToUniversalTime()

Open in new window

0
 

Author Comment

by:amillyard
ID: 20309757
Solar_Flare:

I see -- do you have the equivalent as c# coding?
0
 
LVL 15

Accepted Solution

by:
Solar_Flare earned 2000 total points
ID: 20310394
you mean those 2 lines of VB?
DateTime now = DateTime.Now;
DateTime nowGMT = now.ToUniversalTime();
 

Open in new window

0
Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

 

Author Comment

by:amillyard
ID: 20311271
I am trying to update the @DateTimeStamp table column via a stored procedure -- @DateTimeStamp is structured as a smalldatetime variable.

When processing the update, this column is not changing it details.

is the attached code snippet correct?
DateTime now = DateTime.Now;
DateTime nowGMT = now.ToUniversalTime();
scCommand.Parameters.AddWithValue("@DateTimeStamp", nowGMT);

Open in new window

0
 

Author Comment

by:amillyard
ID: 20311322
found the error - me ! ... looking at the wrong table (for the results)

thank you for your contribution.

I will award you the points for pointing me in the right direction -- but if you have to had an example of the web service for accessing server time (c#) would be much apprieated also.
0
 
LVL 15

Expert Comment

by:Solar_Flare
ID: 20314944
you would just add a .asmx web service file to you web application and it would contain a webmethod. You would then add a web reference to your project pointing to the web service and then you can call it to ask the server for its current time.

in asmx file
[WebMethod]
public DateTime GetServerTime()
{
   return DateTime.Now;
}



in your application
webservicename service = new webservicename();
DateTime serverTime = service.GetServerTime();
0
 

Author Comment

by:amillyard
ID: 20316692
Solar_Flare:

thank you for the above scripting...I am trying to add the web reference.  the problem seems to be that this project is secured (asp username/pw) and keep being returned to login page.  even when entering the correct un/pw, -- can invoke web post for util -- the web reference window is not allowing the web reference to be created.  (below is the error message in this window).

how do I get around this login issue (apart from taking security off?

do these files need to be in an open folder (no access/user retrictions)? -- i.e. available to anyone publically as well?
_____________________________________________

There was an error downloading 'http://localhost:3752/datetimeserver.asmx?op=GetServerTime'.

The request failed with the error message:
--
<html><head><title>Object moved</title></head><body>
<h2>Object moved to <a href="/login.aspx?ReturnUrl=%2fdatetimeserver.asmx%3fop%3dGetServerTime&op=GetServerTime">here</a>.</h2>
</body></html>

-
0
 

Author Comment

by:amillyard
ID: 20316750
Web References :  datetimeServerUS

.cs scripting:

datetimeServerUS service = new datetimeServerUS();
DateTime serverTime = service.GetServerTime();

I am getting the following error:

'FORTUNE.datetimeServerUS' is a 'namespace' but is used like a 'type'
0
 

Author Comment

by:amillyard
ID: 20316801
it ok, I got it to work 100%

again, many thanks :-)
0
 

Author Comment

by:amillyard
ID: 20316821
I need to ask one more thing please, relating to the security of that web service -- as I had to remove security (i.e. asp.net un/pw) -- is there another way of security this service?

many thanks.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

963 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question