Jump to content

Quick date() Question


JSHINER

Recommended Posts

Until (if ever) browsers start passing the client's date/time in the http request headers, you will need to code this yourself.

 

This simplest way would be to use the following method and replace the width/height information with the client's date and time -http://www.php.net/manual/en/faq.html.php#faq.html.javascript-variable

Link to comment
https://forums.phpfreaks.com/topic/91486-quick-date-question/#findComment-468637
Share on other sites

<script type="text/javascript">
<!--
var Days = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');

var today = new Date();
var Hours = today.getHours();
Hours2 = Hours;
Hours = leadingZero(Hours);
var ampm = "am";
if (Hours2 > 11)
ampm = "pm";
if (Hours2 > 12)
Hours2 -= 12;
if (Hours2 == 0) Hours2 = 12;
Hours2 = leadingZero(Hours2);
var Minutes = leadingZero(today.getMinutes());

function takeYear(theDate)
{
x = theDate.getYear();
var y = x % 100;
y += (y < 38) ? 2000 : 1900;
return y;
}

function leadingZero(nr)
{
if (nr < 10) nr = "0" + nr;
return nr;
}

document.write (+ Hours2 + ':' + Minutes + ' ' + ampm);

// -->
</script>

 

Is there ANY way to do this:

 

if(document.write (+ Hours2 + ':' + Minutes + ' ' + ampm)=="10:00 am") { echo 'Morning'; }

 

Not exactly like that I know, but that's basically what I want to do. Any ideas?

Link to comment
https://forums.phpfreaks.com/topic/91486-quick-date-question/#findComment-468856
Share on other sites

Since you asked "Is there a way to get the same info of the users machine" in the php (a server side scripting language) forum, I assumed that you wanted to get that information to a .php script on the server, which using the information in my post above can accomplish.

 

What are you actually trying to accomplish?

Link to comment
https://forums.phpfreaks.com/topic/91486-quick-date-question/#findComment-468903
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.