473,789 Members | 2,624 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Server Time Revisited

I've been testing my web app on another workstation to simulate using
the server time. The test pc's time is an hour behind the server time
and when the user processes a request, the server time is picked up.
The problem is that I've got a "clock" on the web page that updates the
"current time" every second since the app is time critical. The clock
is a jscript routine. It seems to be picking up the local time. I'm
just instantiating a new Date() object (when the page loads), which
according to the docs is making a System.DateTime call. Is there a way
to seed it or get it to pick up the server time instead?

margaret

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #1
5 2458
Margaret,

Use server-side code to write the the arguments for the client-side Date
constructor. See
http://msdn.microsoft.com/library/en...6jsobjdate.asp for
the alternate constructors.

HTH,
Nicole
"sandman" <an*******@devd ex.com> wrote in message
news:uW******** ******@TK2MSFTN GP12.phx.gbl...
I've been testing my web app on another workstation to simulate using
the server time. The test pc's time is an hour behind the server time
and when the user processes a request, the server time is picked up.
The problem is that I've got a "clock" on the web page that updates the
"current time" every second since the app is time critical. The clock
is a jscript routine. It seems to be picking up the local time. I'm
just instantiating a new Date() object (when the page loads), which
according to the docs is making a System.DateTime call. Is there a way
to seed it or get it to pick up the server time instead?

margaret

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 15 '05 #2
Hi Margaret,
These are the constructor available for Date():
new Date()new Date(millisecon ds)new Date(dateString )new Date(yr_num, mo_num,
day_num [, hr_num, min_num, sec_num, ms_num])Parameters
milliseconds Integer value representing the number of milliseconds since 1
January 1970 00:00:00.

dateString String value representing a date. The string should be in a
format recognized by the Date.parse method.

yr_num, mo_num,day_num Integer values representing part of a date. As an
integer value, the month is represented by 0 to 11 with 0=January and
11=December.


as you can see you can set it as you need it, now the tricky part would be
how to transfer the server date to the client, the code below will do it, be
aware I did not test it just write it from OE :)
<%
// Server side code
void WriteDateToClie nt(){
Literal lit = new Literal;
lit.Text = "<script>\n " +
var yr_num=" + DateTime.Now.Ye ar.ToString() + ";\n" +
var mo_num=" + (DateTime.Now.M onth-1).toString() + ";\n"
+ // .Net DateTime.Month is from 1 to 12
var day_num=" + DateTime.Now.Da y.ToString() + ";\n" +
//.. do the same with the Time part
this.Controls.A dd( lit ); // this include the literal in the page control
list
}

%>

//in the client side, you know you have define the variables you are going
to use
<script>
var ServerDate = new Date( yr_num, mo_num, .... );
</script>

Now you have the server time in the client :)
all you have to remember is always call the method in the server side, you
can get this by calling it in the Load handler.
Hope this help,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

----- Original Message -----
From: "sandman" <an*******@devd ex.com>
Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
Sent: Tuesday, October 21, 2003 12:44 PM
Subject: Server Time Revisited

I've been testing my web app on another workstation to simulate using
the server time. The test pc's time is an hour behind the server time
and when the user processes a request, the server time is picked up.
The problem is that I've got a "clock" on the web page that updates the
"current time" every second since the app is time critical. The clock
is a jscript routine. It seems to be picking up the local time. I'm
just instantiating a new Date() object (when the page loads), which
according to the docs is making a System.DateTime call. Is there a way
to seed it or get it to pick up the server time instead?

margaret

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 15 '05 #3
I looked at my code again. I'm getting the server time over there but
the JScript that I'm running at the client side is getting a new Date()
every minute in order to show a "live" clock. That's what's stomping on
the server date. I'm hesitant to ask for the server for the date each
time because of the volume of the requests. When I tried using an
alternative constructor, it never updates because the parameters never
change. So whatever I use to construct the date also has to update
every minute. But there's no such thing as global variables in a
webpage right?

Ignacio, the code for the literal's Text property totally confused me.
It looks like you're declaring variables in the middle of it.

margaret

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 15 '05 #4
Margaret,

You can work around this by storing the offset between the server time and
the client time. When you need to update the displayed time, just adjust
the current client time by the stored offset.

HTH,
Nicole
"sandman" <an*******@devd ex.com> wrote in message
news:eR******** *****@TK2MSFTNG P10.phx.gbl...
I looked at my code again. I'm getting the server time over there but
the JScript that I'm running at the client side is getting a new Date()
every minute in order to show a "live" clock. That's what's stomping on
the server date. I'm hesitant to ask for the server for the date each
time because of the volume of the requests. When I tried using an
alternative constructor, it never updates because the parameters never
change. So whatever I use to construct the date also has to update
every minute. But there's no such thing as global variables in a
webpage right?

Ignacio, the code for the literal's Text property totally confused me.
It looks like you're declaring variables in the middle of it.

margaret

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 15 '05 #5
Hi Margaret,

That's exactly what I'm doing :)
I'm generating Javascript code form the server side, I'm generating a <script> section that will be executed in the client, inside this section I declare the variables I need to init a new Date instance directly in the client but with the server time.
Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"sandman" <an*******@devd ex.com> wrote in message news:eR******** *****@TK2MSFTNG P10.phx.gbl...
I looked at my code again. I'm getting the server time over there but
the JScript that I'm running at the client side is getting a new Date()
every minute in order to show a "live" clock. That's what's stomping on
the server date. I'm hesitant to ask for the server for the date each
time because of the volume of the requests. When I tried using an
alternative constructor, it never updates because the parameters never
change. So whatever I use to construct the date also has to update
every minute. But there's no such thing as global variables in a
webpage right?

Ignacio, the code for the literal's Text property totally confused me.
It looks like you're declaring variables in the middle of it.

margaret

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 15 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
15230
by: Ken Lindner | last post by:
I have a need to become familiar with SQL Server 2000 for work. Needless to say I am new to SQL Server any version, but not IT in general. My employer has provided me with the SQL Server 2000 Personal disk from the SQL Server 2000 Enterprise kit as this is reported here on the MSDN web site to be the version that is supported on Windows XP. In fact so many of you kind people confess to having succeeded in doing it. I have tried...
5
3659
by: Phil Grimpo | last post by:
I have a very odd situation here. I have an administration page, where based on a users permissions, a recordset is called from the SQL server which has a list of paths to "Module Menus". Each of these menus are then placed into the page by calling Server.Execute(rs_Modules("ModulePath")). This works fine for up to 15 "menus" After that, the session variables that were set (not including those called by Global.ASA) are no longer set. ...
15
4491
by: Michael Rybak | last post by:
hi, everyone. I'm writing a 2-players game that should support network mode. I'm now testing it on 1 PC since I don't have 2. I directly use sockets, and both client and server do computations, the only data transfered is user mouse/kbd input. It works synchronously, but somehow, when I play in client window, both client and server have 17 fps, while when playing in server window, server has 44 fps while client ...
6
2198
by: Rich_C | last post by:
Can anyone tell me why this code doesn't work? The original came from an example in this group, but was modified slightly when the original failed to return message details. I am able to connect to the server and see the number of messages on the server, but message details (sender, subject, body, etc.) are not returned. _______________ Dim Mailer
0
1181
by: Saintor | last post by:
I use the calendar from S. Lebans and it is great. Except this time, I would need a calendar that I could select TIME as well for use with Access 97. Do you have something to suggest ? If possible not a an ActiveX control, but form-based. TIA.
14
2590
by: Urs Thuermann | last post by:
What is the most elegant way to check certain conditions at compile time? I.e. I want a compile time error to be generated if for example the size of a struct is not a multiple of 4 or if one struct is larger than another struct, etc. I think of something like #define CHECK(expr) static int dummy CHECK(sizeof(struct foo) % 4 == 0);
2
2070
by: seb | last post by:
Hi, this simple server (time protocol) does not respond after a few hours, even when it is restarted. The behaviour looks to me like a firewall blocking but I have desabled the firewall. Using Netstat - a I find the server listed when it is running and not listed when I stop it. The server starts whith no error. But after about 6-8 hours there is no way to make it respond again (even when it is restarted). Once it is blocked, I killes...
1
2744
by: danfolkes | last post by:
Hey Everyone, I am trying to send repeated messages from a "Node" to a "Server". It works the first time I send the from the Node to Server, but after that it either errors, or does not do anything. I would love some help, here is the code: import socket import thread import time
2
1659
by: KeithWalton | last post by:
I know this has been discussed before, but my database is getting huge. Every night I restore backups of my databases to a report server. I don't need the logs, so after restore I detach the database and delete the logs. When I reattach, SQL Server creates new log files that are tiny. If I can do this, why do I need the log files in the first place? As it is, I have to stagger my database restores because I don't have room for the 400 GB of...
0
9666
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9511
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9020
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7529
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6769
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5417
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3700
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2909
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.