View Full Version : internet date ??
wouter
11-18-2002, 07:40 AM
dear all,
i need something basic : the current date
..... with the following restrictions
- i cannot rely on the computer date since it can be set incorrect
- i dont have a cgi-bin, asp or something simular on the server side
... so it must be CGI remotely hosted like
<SCRIPT LANGUAGE="JavaScript" SRC="http://scripts.cgispy.com/date.cgi"></SCRIPT>
but extra restriction
i need it in a Javascript var so I can use it for calculations and translation. Parse it after input in a form?
anyone any idea or something else -- thanks Wouter
Roy Sinclair
11-18-2002, 09:04 PM
- i dont have a cgi-bin, asp or something simular on the server side
This is going to make what you want impossible.
... so it must be CGI remotely hosted
You were ok this far but...
need it in a Javascript var so I can use it for calculations and translation
When you added this you run smack into a restriction on javascript where it cannot use any content that's not from the same site as the page the script is running on. This restriction is in place to prevent the active theft of content on one site by another site which is very necessary but it also means that you cannot do what you want.
Your best bet may be to find another host where a server side script of some sort is possible.
beetle
11-18-2002, 09:09 PM
Originally posted by Roy Sinclair
When you added this you run smack into a restriction on javascript where it cannot use any content that's not from the same site as the page the script is running on.Huh? I can src any absolute JS file I want...unless it contains code to stop me (which some do)
Roy Sinclair
11-18-2002, 10:16 PM
Originally posted by beetle
Huh? I can src any absolute JS file I want...unless it contains code to stop me (which some do)
But that's not the problem, his problem is getting the correct time from an outside source (not the client system). Just sourcing a remotely hosted script wouldn't get him the time.
beetle
11-18-2002, 10:54 PM
You can use my date class to test this. Maybe your server supports SSI. Save this page as test.shtml, upload it and check it out...<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Test Server Date vs. System Date</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script>
function myDate(dateStr) {
var months = ['January','February','March','April','May','June','July','August','September','October','November',' December'];
var days = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
if (typeof dateStr != 'undefined') {
var d = new Date(dateStr);
this.dateString = dateStr;
}
else
var d = new Date();
this.epoch = d.getTime();
this.year2 = d.getYear();
this.year4 = d.getFullYear();
this.leap = (this.year4 % 400 == 0) ? true : (this.year4 % 4 == 0 && this.year4 % 100 != 0) ? true : false;
this.mnth = d.getMonth();
this.month = this.mnth + 1;
this.monthName = months[this.mnth];
this.dy = d.getDay();
this.day = this.dy + 1;
this.dayName = days[this.dy];
this.date = d.getDate();
this.hours24 = d.getHours();
this.hours12 = (this.hours24 == 0) ? 12 : (this.hours24 > 12) ? this.hours24-12 : this.hours24;
this.minutes = d.getMinutes();
this.seconds = d.getSeconds();
this.ampm = (this.hours24 == 0) ? "am" : (this.hours24 >= 12) ? "pm" : "am";
this.GMTstring = d.toGMTString();
this.offset = d.getTimezoneOffset();
}
function myDate.prototype.dump() {
var a = "Property\t:\tValue\n------------------------\n";
for(var i in this)
if (i != 'dump') a += i + "\t:\t" + this[i] + "\n";
alert(a);
}
</script>
</head>
<body>
<script>
<!--#config timefmt="%A, %B %d %Y %H:%M:%S" -->
var ssiDate = new myDate("<!--#echo var="DATE_LOCAL" -->");
ssiDate.dump();
var today = new myDate();
today.dump();
</script>
</body>
</html>
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.