Update Date/Time Button

This is a discussion on "Update Date/Time Button" within the JavaScript Forum section. This forum, and the thread "Update Date/Time Button are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Aug 8th, 2007, 14:00
New Member
Join Date: Aug 2007
Location: San Antonio, TX
Age: 21
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Update Date/Time Button

I am wanting to use the server time, or a specific time zone (-5 GMT) to have the update date/time button refer to. Right now this script references the users local time when they click the update date/time button.

My problem is simply that I have many users in different time zones, and when they update an entry, it doesn't make any logical sense to the other time zones. So to make it logical, if they are seeing the same time it can be related to one another.

Thank you for any help!

<html>
<head>
<script language="jscript" type="">
function setcompleted()
{
var myDate = new Date();

var str = (myDate.getMonth()+1) + "/" + pad(myDate.getDate()) + "/" + myDate.getFullYear();

str += " " + pad(myDate.getHours()) + ":" + pad(myDate.getMinutes());

document.forms[0].date_time.value=str;
}
function pad(num)
{
if (num &lt; 10)
return "0" + num;
else
return num;
}
</script>

</head>
<body>
<form>
<input type="text" value="_currentdatetime" name="date_time" required="false"></input>
<button language="jscript" onClick="return setcompleted()">Update Date/Time</button>
</form>
</body>
</html>
Reply With Quote

  #2 (permalink)  
Old Aug 8th, 2007, 14:20
Junior Member
Join Date: Jul 2007
Location: Dallas, TX
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Update Date/Time Button

The javascript you are using is asking the users' computer what its internal date/time is. This is why all of the times appear different when your users post from different time zones.

If your site is made in PHP or ASP and is capable of using SSI (server-side includes), you might find this article useful:

http://www.dynamicdrive.com/dynamicindex6/localtime.htm

You might also try this javascript that I found here:

http://javascript.internet.com/time-...avascript.html

Code: Select all
 
<!-- THREE STEPS TO INSTALL SERVERDATE TO javascript:
  1.  Save the code in a file called "servertime.php"
  2.  Copy the coding into the HEAD of your HTML document
  3.  Add the last code into the BODY of your HTML document  -->
<!-- STEP ONE:  Paste this code in a file called "servertime.php"
 (without the quotes) and place it in the main directory of your site.
 Change mode to executable - chmod 755  -->
 
<?php
/* Copyright 2005 Emery Wooten - www.mresoftware.com
 This script is called from Javascript. It should be called before any
 JavaScripts that use the date.
 Place the statement below in the <head> section of your HTML page:
 <script type="text/javascript" src="servertime.php"></script>
*/
// Supress errors
error_reporting(0);
/* If your server is not in your time zone, adjust it here.  Mine is 1 hour East of me.
To use this variable, you will need to remove the "//".
// $myServerOffset = (+1) * 3600;
// Get server date
$mydate = date("U");
// Get Timezone offset
$myoffs = date("Z") - $myServerOffset;
// Adjust offsets for local machine
print "var tzoffset = $myoffs + (new Date().getTimezoneOffset()*60);";
// Set JavaScript variable to your server time as seen from client machine's location.
print "var servertimeOBJ=new Date(($mydate+tzoffset)*1000);";
?>
 
<!-- STEP TWO: Paste this code into the HEAD of your HTML document  -->
<HEAD>
<script language="JavaScript" src="servertime.php"></script>
<script type="text/javascript">
<!-- Begin
/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Emery Wooten :: www.mresoftware.com */
// First thing, reference the variable.
var servertimeOBJ;
// Now check that it is set
if (servertimeOBJ != null){
 var myscriptTime = servertimeOBJ;
}
// If server time not passed, use client's time
else{
 var myscriptTime = new Date();
}
/* "myscriptTime" is a variable local to this script. Name it as you wish.
 After the above code is executed, this local variable is used for all date/time
 calculations performed by the script. If all works, this variable
 contains the server date as a proper JavaScript date object. */
// End -->
</script>
</HEAD>
 
<!-- STEP THREE: Copy this code into the BODY of your HTML document  -->
 
<BODY>
<script type="text/javascript">
<!-- Begin
  document.write(myscriptTime)
// End -->
</script>
<p><center>
<font face="arial, helvetica" size"-2">Free JavaScripts provided<br>
by <a href="<A href="http://javascriptsource.com">The">http://javascriptsource.com">The JavaScript Source</a></font>
</center><p>
<!-- Script Size:  2.48 KB -->
I haven't used either of these, but both DynamicDrive and The JavaScript Source are helpful resources I've used many times in the past.

I hope this helps.
Reply With Quote
  #3 (permalink)  
Old Aug 8th, 2007, 14:25
New Member
Join Date: Aug 2007
Location: San Antonio, TX
Age: 21
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Update Date/Time Button

Where I am posting this information it is strictly html - javascript.
Reply With Quote
Reply

Tags
date, form, server time, time, update

Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Date & Time [Combine] doctypedeclaration JavaScript Forum 3 Mar 12th, 2008 01:22
Can't open the date time picker yuenli JavaScript Forum 0 Jul 3rd, 2007 07:22
Access date field - update as record is updated matrixbrawl Databases 0 Jan 10th, 2007 09:58
Creating Date & Time SweetLou Classic ASP 1 Jan 23rd, 2006 13:55
Server time and date script gribble JavaScript Forum 1 Aug 16th, 2005 09:53


All times are GMT. The time now is 19:14.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43