Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Client System Time 1

Status
Not open for further replies.

army001

Programmer
Apr 11, 2003
12
US
Never had to deal with time issues before so i have a quick question, what is the best way to get the time and date from the client to the page.

This is what i am trying but no luck, the values of dt1 - 3 are not being considered integers. I tried using val() but the strings can be converted.

<!--- Parses the client's system time into hour, minutes and seconds for CF to create a readable time ---> <script language=&quot;JavaScript&quot; type=&quot;text/javascript&quot;> var today = Date(); date_parsed = today.split(&quot; &quot;); ptime = date_parsed[3].split(&quot;:&quot;); </script>

<!--- Break down each array item into a CF variable ---> <cfset t_hour=&quot;<script language='JavaScript' type='text/javascript'>document.write(ptime[0])</script>&quot;> <cfset t_minutes=&quot;<script language='JavaScript' type='text/javascript'>document.write(ptime[1])</script>&quot;> <cfset t_seconds=&quot;<script language='JavaScript' type='text/javascript'>document.write(ptime[2])</script>&quot;>

<!--- Create a time object readable by CF ---> <cfset con_time = CreateTime(t_hour,t_minutes,t_seconds)>

 
i don't think you can mix cllient-side and server-side code like that

what does &quot;get the time and date from the client to the page&quot; mean?

why does the client's time matter? the client's computer might have a faulty clock setting

the only way to send stuff from the client (browser) to CF is via a GET or POST


rudy
 
If you try the code it works in bringing the javascript variable to Coldfusion. I am trying to get correct timestamp for any client in any part of the world into the data being stored by the client. If a clients time is off that is their issue.

What I mean by &quot;get time and date from the client to the page&quot; is the time that is in their system displayed and usable in the coldfusion application their are using.

i.e. You access my website from your computer, you sign-up for a free on-line calendar. You post an event to your calendar. The time and date must be specific to your time zone correct? What is the best way of accomplishing that?
 
i don't see how setting a cf variable to a string of code will generate a time in cf -- the string of code is not executed by cf when the cf variable is set

the best way to send the time from the client to cf is with a form field

rudy
 
First I would like to say i appreciate the fast response this forum has.

Rudy please click on this link and you can see what i mean. The problem is that the strings for the client time are not numbers and i cant get them to be recognized that way. CF tells me that they must be integers to use for CreateTime() function.

Thank You.
 
yes, that's what i'm saying, those are strings and will remain as strings while within cf

cf does not execute browser javascript, you can't mix client-side and server-side code like that

on the page that the clients use to submit their entry, have an input field for the datetime value

this datetime value should be pre-populated by the server (for non-javascript users) and then you can have a javascript routine re-write it with the client's datetime

send this input field along with the other form fields and cf can then use it when storing the client's other data

rudy
 
Okay... one more time.

As Rudy says, the javascript - which is client-side - will execute after the CFML - which is server-side.

Thus, as ColdFusion is processing the page, it is literally seeing the javascript code/variables as strings (t_seconds is being set to &quot;<script language='JavaScript' type='text/javascript'>document.write(ptime[2])</script>&quot; , rather than the evaluation of that javascript code).

There is no way to set a ColdFusion variable to the value of a javascript variable because of the order in which this processing takes place. You would need to set the value of a form field to the value of the javascript variable and submit it back to ColdFusion in order for CF to ever know what the value is.

Your example page works because you are using javascript to output the client-side time and ColdFusion to output the server-side time (pull up the page and do &quot;View source&quot;... see how the client time is still a bunch of javascript, while the server time is actually rendered HTML). And this would be the only way you'd be able to do this, unless you did a form submit.

BUT, you could do an initial form submit to establish the user's client-side time offset (delta from GMT) and store that value in a session variable... so you only need to ask them to submit a form once.

-Carl
 
Yeah, but what a problem with just getting time offset is the date, if I know the user is 3 hours ahead then fine i know if its 10pm at the servers it 1am there, but now the server has 4/11 and the client is on 4/12. How do i figure that one. I'm sorry i have been working so many problems here that my brain is being fried. This one has eluded me.

Thanks, Jason.
 
jason, have a look at this page:


see how javascript creates a string for the client's current datetime (it may not be the swiftest javascript, but it gets the job done)

coldfusion pre-populates the form field with the server's time (my server's in mountain time, north america)

then the body onload javascript overwrites the contents of the input field with the browser's time

this accommodates any users who have javascript turned off

when the form is submitted, whatever was in the field is first tested using coldfusion's IsDate function

if you enter crap, it tells you it's not a valid datetime

now, your clients don't have to actually type their current datetime into a field, you could do it all in a hidden form field

rudy
 
It would all be handled in the offset. That's the brilliant thing about GMT. An offset of +8 hours is still 8 hours ahead of GMT, no matter whether GMT is 01:00 or 23:00.

If your local GMT offset is +8, and it's 7:00 in the morning of April 11th at the meridian, it's 3:00 in the afternoon on April 11th, local time.

If it's 11:30 at night on April 11th at the meridian, it's 7:30 in the morning on April 12th, local time... but in ColdFusion, that's still just Now() plus 8 hours.


-Carl
 
Thanks for the help guys. With all this information i can get it working.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top