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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.