Jump to content

user server/ip $time?


paulmo

Recommended Posts

<script type="text/javascript">
function GetClientUTC()
{
var now = new Date();
var offset = now.getTimezoneOffset();
return offset;
}
</script>

 

Unsure if that works, but yea, you could use that and post the offset to your script on user login and use that via session to change the offset.

Link to comment
https://forums.phpfreaks.com/topic/137532-user-serverip-time/#findComment-718754
Share on other sites

how to echo my $time keywords (morning, afternoon evening) with your js, premiso? there's no user log in on my page/site.

 

and this from mradam's link also seems relevant (but again, don't know how to integrate):

<script type="text/javascript">
var d = new Date();
document.write (d.toLocaleTimeString());
</script>

 

thanks for help.

Link to comment
https://forums.phpfreaks.com/topic/137532-user-serverip-time/#findComment-719110
Share on other sites

  • 2 weeks later...

getting a parse error on line 61 "<script type=" which looks fine to me. trying to get user local time to work right with the morning afternoon evening statement. help please? and thanks:

<script type="text/javascript">
function.GetClientUTC()
{
var now = new Date();
var offset = now.getTimezoneOffset();
return offset;
}
</script>

$time = (GetClientUTC() < 12) ? 'morning' : (intval(date('G')) < 17) ? 'afternoon' : 'evening';

Link to comment
https://forums.phpfreaks.com/topic/137532-user-serverip-time/#findComment-724890
Share on other sites

Well yea it will not work. You are mixing JS and PHP. They are two different languages JS has to be done on the client side. So in order for this to work you will have to setup a page that loads before anything else is loaded and set the locale probably as a cookie using javascript. Then take it to the original page and access the locale from the cookie.

 

 

Link to comment
https://forums.phpfreaks.com/topic/137532-user-serverip-time/#findComment-724892
Share on other sites

Using cookies works well

<script type="text/javascript">
var myDate = new Date();
var myTime = myDate.toLocaleTimeString();
myDate.setDate(myDate.getDate()+1);
setCookie('UserTime',myTime);

function setCookie(c_name,value,expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}
</script>

<?php
list($hours, $minutes, $seconds) = explode(":",$_COOKIE['UserTime']);
echo "Its $hours:$minutes:$seconds";
$time = ($hours < 12)?'morning'($hours < 17)?'afternoon':'evening');
echo $time;
?>

Link to comment
https://forums.phpfreaks.com/topic/137532-user-serverip-time/#findComment-724929
Share on other sites

alas, the $time statements are not matching the clock time. for example, just now i'm getting

The time is 7:28:30 PM Good morning 

 

here's the code. thanks for help!

 

<script type="text/javascript">
var myDate = new Date();
var myTime = myDate.toLocaleTimeString();
myDate.setDate(myDate.getDate()+1);
setCookie('UserTime',myTime);

function setCookie(c_name,value,expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}
</script>

<script type="text/javascript" src="jquery-1.2.6.min.js"></script>     
<script type="text/javascript" src="jquery.corners.min.js"></script>
          
<div id="col1">

<div style="background-color:#FFFFFF; padding:10px" class="rounded {10px}">
<?php
list($hours, $minutes, $seconds) = explode(":",$_COOKIE['UserTime']);
echo "The time is $hours:$minutes:$seconds";
$time = ($hours < 12)?'morning'($hours < 17)?'afternoon':'evening');
echo " Good $time";
?>

Link to comment
https://forums.phpfreaks.com/topic/137532-user-serverip-time/#findComment-725817
Share on other sites

actually the time of day [morning afternoon evening] is still not matching up with time, which is accurate. i've tried both $time statements:

<?php
list($hours, $minutes, $seconds) = explode(":",$_COOKIE['UserTime']);
echo "The time is $hours:$minutes";  [correct]

//$time = ($hours < 12)?'morning'($hours < 17)?'afternoon':'evening');
$time = intval(date('G')) < 12 ? 'morning' : intval(date('G')) < 17 ? 'afternoon' : 'evening'; [not]
echo " on this ".date('l') ; [correct]
echo " {$time}.";[not]

Link to comment
https://forums.phpfreaks.com/topic/137532-user-serverip-time/#findComment-726135
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.