JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Closed Thread
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 5th, 2007, 01:35 AM
Flash Gordon Flash Gordon is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2007
Posts: 38 Flash Gordon Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 4 h 55 m 34 sec
Reputation Power: 0
Date with server timestamp.

Hi Gang,

Why does this JS script return the client's local time and not the server's time?

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>


<script type="text/javascript">
<!--
	var timestamp;
	<?php echo "timestamp = " . (mktime() * 1000); ?>
	
	
	function time()
	{
		var date     = new Date(timestamp);
		var hours    = date.getHours();
		var minutes  = (date.getMinutes() < 10) ? "0" + date.getMinutes() : date.getMinutes();
		var seconds  = (date.getSeconds() < 10) ? "0" + date.getSeconds() : date.getSeconds();
		var pst      = (hours>11) ? "PM" : "AM";
		var phrase   = "local time = ";
		timestamp    += 1000;
		
		//return phrase + ((hours%12==0) ? 12 : (hours%12)) + ":" + minutes + ":" + seconds + " " + pst; 
		return phrase + hours + ":" + minutes + ":" + seconds + " " + pst; 
	}
	
	function show()
	{
		document.getElementById("clock").firstChild.nodeValue = time();
	}
	
	window.onload = init;
	
	function init()
	{
		show();
		setInterval("show()", 1000);
	}
-->
</script>
</head>

<body>
	<span id="clock">&nbsp;</span><br  />
	<span id="clock2">Server time = <?php echo date("g:i A", mktime()); ?> </span> <br  />
	<span id="timestamp">php timestamp = <?php echo mktime(); ?> </span> <br  />
</body>
</html>

Reply With Quote
  #2  
Old April 5th, 2007, 01:37 AM
draelon draelon is offline
Dissident
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Mar 2003
Location: New York
Posts: 1,671 draelon User rank is Sergeant Major (2000 - 5000 Reputation Level)draelon User rank is Sergeant Major (2000 - 5000 Reputation Level)draelon User rank is Sergeant Major (2000 - 5000 Reputation Level)draelon User rank is Sergeant Major (2000 - 5000 Reputation Level)draelon User rank is Sergeant Major (2000 - 5000 Reputation Level)draelon User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Day 8 h 8 m 13 sec
Reputation Power: 48
Because javascript is a client side technology.
__________________
Draelon


PHP Manual :: MySQL Manual :: How to Ask Questions the Smart Way
=======================================================

Reply With Quote
  #3  
Old April 5th, 2007, 03:20 PM
Flash Gordon Flash Gordon is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2007
Posts: 38 Flash Gordon Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 4 h 55 m 34 sec
Reputation Power: 0
so what? I'm passing it a timestamp and therefore doesn't matter.

Reply With Quote
  #4  
Old April 5th, 2007, 05:51 PM
sizablegrin's Avatar
sizablegrin sizablegrin is offline
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Jun 2005
Posts: 5,964 sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 3 Weeks 2 Days 12 h 47 m 19 sec
Warnings Level: 10
Number of bans: 1
Reputation Power: 4851
I don't believe that a timestamp is a valid form of data for the Date () constructor (I think they all require a string). Consequently, it's probably just constructing with the current date.
Comments on this post
Tukaro agrees: Nope. I don't know how Date() handles bad input, but that sounds reasonable
Flash Gordon disagrees: RTFM before you make statements you don't know about

Reply With Quote
  #5  
Old April 5th, 2007, 09:44 PM
Tukaro's Avatar
Tukaro Tukaro is offline
Standing 3 feet to the left.
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jan 2006
Location: USA
Posts: 1,435 Tukaro User rank is First Lieutenant (10000 - 20000 Reputation Level)Tukaro User rank is First Lieutenant (10000 - 20000 Reputation Level)Tukaro User rank is First Lieutenant (10000 - 20000 Reputation Level)Tukaro User rank is First Lieutenant (10000 - 20000 Reputation Level)Tukaro User rank is First Lieutenant (10000 - 20000 Reputation Level)Tukaro User rank is First Lieutenant (10000 - 20000 Reputation Level)Tukaro User rank is First Lieutenant (10000 - 20000 Reputation Level)Tukaro User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 5 Days 3 h 49 m 16 sec
Reputation Power: 184
Send a message via AIM to Tukaro Send a message via MSN to Tukaro
As sizablegrin said, the timestamp is not in the correct format for creating a new Date.

Quick guide for creating a date. As you can see, Date() will take a string, but it has to be in a specific format. It will not take in a single number.

Are you not getting a Javascript error after the page loads? (and perhaps every second afterwards).

Reply With Quote
  #6  
Old April 5th, 2007, 11:25 PM
Flash Gordon Flash Gordon is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2007
Posts: 38 Flash Gordon Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 4 h 55 m 34 sec
Reputation Power: 0
NO...it takes an integer.

LINK

new Date(milliseconds)
milliseconds
Integer value representing the number of milliseconds since 1 January 1970 00:00:00 UTC.

It takes an integer, or it will take a string.

Reply With Quote
  #7  
Old April 6th, 2007, 06:45 AM
Tukaro's Avatar
Tukaro Tukaro is offline
Standing 3 feet to the left.
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jan 2006
Location: USA
Posts: 1,435 Tukaro User rank is First Lieutenant (10000 - 20000 Reputation Level)Tukaro User rank is First Lieutenant (10000 - 20000 Reputation Level)Tukaro User rank is First Lieutenant (10000 - 20000 Reputation Level)Tukaro User rank is First Lieutenant (10000 - 20000 Reputation Level)Tukaro User rank is First Lieutenant (10000 - 20000 Reputation Level)Tukaro User rank is First Lieutenant (10000 - 20000 Reputation Level)Tukaro User rank is First Lieutenant (10000 - 20000 Reputation Level)Tukaro User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 5 Days 3 h 49 m 16 sec
Reputation Power: 184
Send a message via AIM to Tukaro Send a message via MSN to Tukaro
I apologize, I was unaware of that. Looking at your code, I assume you've already tested the output of mktime to ensure it was different than what Javascript was giving.

In that case, I can't see why it would be affecting it. When I return from class I'll try running it on my own PHP host to see if I can remedy the problem from there.

Reply With Quote
  #8  
Old April 6th, 2007, 10:51 AM
sizablegrin's Avatar
sizablegrin sizablegrin is offline
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Jun 2005
Posts: 5,964 sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 3 Weeks 2 Days 12 h 47 m 19 sec
Warnings Level: 10
Number of bans: 1
Reputation Power: 4851
You are correct. It can take an integer.

Referring to both the PHP manual and the document you linked, I think this is what happens. (My system performs as yours, gives me the local time, despite the fact that my server is 3 timezones away).

The integer returned by MKTIME, as used, represents UTC.

The date object contains both UTC and local time (presumably as defined by the locale settings). The methods used are the local-time methods.

That's my take on it.
Comments on this post
Flash Gordon agrees: Admitting I'm correct is the only smart thing you said in this thread.....

Reply With Quote
  #9  
Old April 6th, 2007, 03:53 PM
Flash Gordon Flash Gordon is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2007
Posts: 38 Flash Gordon Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 4 h 55 m 34 sec
Reputation Power: 0
Hey guys,

Thanks for still looking into this....

I've tried several methods and always the timestamp is ignored by JS

var date = new Date((timestamp-27000)); still outputs local time.

Quote:
The date object contains both UTC and local time (presumably as defined by the locale settings). The methods used are the local-time methods.
. Yea I was thinking that too, but I tried the getUTCHours() method and it gets the real GMT/UTC time and ignores the timestamp too. Passing a timestamp in the constructor seems rather pointless if there are no methods to take advantage of it.....

Reply With Quote
  #10  
Old April 8th, 2007, 12:55 PM
Flash Gordon Flash Gordon is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2007
Posts: 38 Flash Gordon Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 4 h 55 m 34 sec
Reputation Power: 0
bump*

Reply With Quote
  #11  
Old April 9th, 2007, 02:13 PM
Flash Gordon Flash Gordon is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2007
Posts: 38 Flash Gordon Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 4 h 55 m 34 sec
Reputation Power: 0
no love?

Reply With Quote
  #12  
Old April 9th, 2007, 02:51 PM
sizablegrin's Avatar
sizablegrin sizablegrin is offline
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Jun 2005
Posts: 5,964 sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 3 Weeks 2 Days 12 h 47 m 19 sec
Warnings Level: 10
Number of bans: 1
Reputation Power: 4851
You aren't thinking. Suppose you call me and ask what time it is, not knowing what time zone I'm in. I get the UTC time and give it to you. You can either show it as UTC or your local time. Unless I modify it (correctly, to my local time) before I give it to you, you can't know what my time is.
Comments on this post
Flash Gordon disagrees: Your analogies are spectacular. However, you are just missing the point

Reply With Quote
  #13  
Old April 9th, 2007, 09:29 PM
Flash Gordon Flash Gordon is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2007
Posts: 38 Flash Gordon Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 4 h 55 m 34 sec
Reputation Power: 0
No....I get it just fine. That is what a timestamp does.

I take it no one knows or cares to answer on this forum.
Comments on this post
sizablegrin disagrees: I disagree strongly, but with uncharacteristic restraint.

Reply With Quote
  #14  
Old April 9th, 2007, 10:14 PM
sizablegrin's Avatar
sizablegrin sizablegrin is offline
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Jun 2005
Posts: 5,964 sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 3 Weeks 2 Days 12 h 47 m 19 sec
Warnings Level: 10
Number of bans: 1
Reputation Power: 4851
Quote:
Originally Posted by PHP manual for mktime
int mktime ( [int $hour [, int $minute [, int $second [, int $month [, int $day [, int $year [, int $is_dst]]]]]]] )

Returns the Unix timestamp corresponding to the arguments given. This timestamp is a long integer containing the number of seconds between the Unix Epoch (January 1 1970 00:00:00 GMT) and the time specified.

In your case, the time specified is nada. There is nothing here about the server considering its own time zone in providing this value. It is copying that value into a JS expression to be reproduced on the browser. Your browser uses this for a Date object. Your Date object can give you GMT (not precisely the same as UTC, incidentally, but synchronized frequently), or your Date object can give you the local time for that GMT time, according to your locale. If you want the server to give its local time, adjust the timestamp accordingly and feed THAT into your JS assignment.

You've gotten a lot of responses. That's hardly indicative of "no one on this forum knowing or caring." Because you're not paying attention, and because you're frustrated, you're making unwarranted remarks.
Comments on this post
Flash Gordon disagrees: your and idiot

Last edited by sizablegrin : April 9th, 2007 at 10:16 PM.

Reply With Quote
  #15  
Old April 10th, 2007, 01:12 AM
Flash Gordon Flash Gordon is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2007
Posts: 38 Flash Gordon Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 4 h 55 m 34 sec
Reputation Power: 0
Hmm....you really have no clue what you are talking about!

Quote:
In your case, the time specified is nada.

Absolutely not so! Go learn a little php before you make that remark.

Quote:
There is nothing here about the server considering its own time zone in providing this value.
Are you stupid?
What exactly do you think <?php echo date("g:i A", mktime()); ?> displays?

And everything else you said is wrong too. Stop spaming the thread and stop telling people lies. You are missing leading people.

Fool....

this forum is waste of time if this is the response I'm going to get.
Comments on this post
sizablegrin disagrees: You're the fool. You're discussing "date", there, not "mktime".

Reply With Quote
Closed Thread

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > Date with server timestamp.

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap